I don’t know exactly why, but I’ve never been able to set any breakpoint directly into my MVC views while using Visual Studio 2010. Although it allows you to do so into the razor code blocks, it doesn’t seem to work well when dealing with inline razor code.

Breakpoint inside a code block

Breakpoint inside a code block

Thankfully, new Visual Studio RC 2012 allows you to set any breakpoints in your views no matter where they are placed inside the view, but if you still work with Visual Studio 2010 and you haven’t still solved this problem, this will come very handy.

VS RC 2012 MVC view breakpoint in inline razor code.

As we just said before, if you try to set the breakpoint as usual, nothing will happen. There’s a secret, though, to make it work for you nicely and start debugging all your views.

The point is that you have to move the cursor just over the line you want to set the breakpoint on. And when I say over the line it means over the text itself. If you put it over the breakpoints column it won’t work. Then right click your mouse to display a menu like this:

Setting the breakpoint

You then have to put your mouse over the Breakpoint menu and you will see a new submenu appearing with a nice Insert Breakpoint text there. Select it and here you are, you’re desired breakpoint is already set and working.

Breackpoint in inline razor using VS 2010