Search code examples
visual-studio-2010asp.net-mvc-4svnvisual-studio-debugging

Debugging from a View file


Working on a C# MVC project, I can have multiple files open in Visual Studio. When I press F5 to start debugging, the debugging starts if the currently open file is:

  • a controller (*.cs);
  • a model (*.cs);
  • a stylesheet (*.css);
  • a config file (*.config);
  • a partial view (*.cshtml)

However, if the open file is a View (*.cshtml), the browser opens with the "Server Error - URL not found" page.

Additional info: The solution has always been under source control with SVN but at some point, the repository location changed and from then on (I think), this strange error occurs. It didn't happen before, I could debug without thinking if a view file was open or not. The change wasn't performed by me and I lack details on it. I am not sure these things are related either.

Anyone has come across a similar issue? How to solve it?


Solution

  • I am guessing the problem is your project setup. Do following:

    Project right click -> Properties -> Web -> Start action

    Most likely it has "Current page" checked, which does not play well with ASP.NET MVC view, it just tries to open the view directly, and not via route. Every other type of file you mentioned is not detected as page, and thus VS does not try to open them as such.

    You might want to choose a "Specific URL" there, or just make a habit of switching to a different file before hitting F5.