0

I'am facing a weird problem with a mvc project (visual studio premium 2013). Whenever I make even the smallest change to a .cshtml view, I always receive a "Server Error in '/' Application The resource cannot be found." I must clean and rebuild my project several times for it to work. But if, after a change (just a simple modification in the .cshtml view ), I put a break point somewhere in the code being executed in the controller when this view is requested by the browser, then every thing works fine, no error and the change is immediately reflected in the browser. Being new to mvc (but not to .net asp.net, i am coming from web forms), I'm trying to understand some key concepts.

I have changed my default routing to:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Index", action = "GetIndexPage", id =      UrlParameter.Optional }
        );

You can see that I have changed the default names: Home --> Index, action Index --> GetIndexPage

I have also updated the code in my controller accordingly:

        IndexController
             GetIndexPage()
                   return View(...)

As I said this works fine the first time, or after several clean and build solution or a break point inside GetIndexPage()

Using the integrated debugger of the Chrome Browser I saw this exception:

HttpException: A public action method "Index" was not found on controller IndexController
at System....Controller.HandelUnknownAction(string actionname)

Why is it looking for an action Index while in my default settings I have specifically mentionned "GetIndexPage"?

tereško
  • 58,060
  • 25
  • 98
  • 150
TheSoul
  • 4,906
  • 13
  • 44
  • 74
  • This is tricky. Are you using the Development server or IIS Express (in your Project properties)? Also, you can `override` the protected method `HandleUnknownAction`, set a breakpoint and look into the controllercontext's route dictionary ('controller' and 'action' keys) to determine exactly where MVC thinks it should look. – Christopher Stevenson Aug 02 '14 at 22:37
  • Typically, weird errors link this are the product of non-refreshed debug dlls. You can clear out the 'obj' and 'bin' folders in your project and rebuild. That may help. – Christopher Stevenson Aug 02 '14 at 22:38
  • I just ovveride then "HandleUnknownAction" handler and in the RouteData dictionary the values are "Index" for controller and "Index" for action instead of "Index" and "GetIndexPage". Also I use the Development server IIS express of visual studio. If this is an issue from 'obj' and 'dll' folders, is there an option to do that automatically before any run instead of doing that manually for every modification? Thank you for your quick answer! – TheSoul Aug 02 '14 at 23:07
  • Do you have any other routes defined before this one that could be causing the problem? –  Aug 02 '14 at 23:31
  • Now I can see that it works on every second run: whenever I make a change, I receive the error the first time I run the project immediately after the change. But when I run it the second time, every thing works perfectly. There must definitely be a problem with .dlls and deployment ( I am using Chrome and Firefox for my tests) – TheSoul Aug 02 '14 at 23:33
  • @Stephen Muecke, no this is the only route configured – TheSoul Aug 02 '14 at 23:34
  • 1
    Here is a similar question I found but without an answer http://social.msdn.microsoft.com/Forums/en-US/90bee50e-6a01-458d-8235-a2b6e0fb369a/mvc-4-modifying-view-requires-project-rebuild-to-reflect-changes-on-iis-express?forum=Offtopic – TheSoul Aug 02 '14 at 23:43
  • Do you have any views with `@using (Html.BeginForm(new { ReturnUrl = ...` where you may be setting the `ReturnUrl` to an incorrect value? –  Aug 03 '14 at 01:04
  • @stephen no. url is set only through routing configuration. – TheSoul Aug 03 '14 at 01:16
  • It's definitely a glitch in dlls. If you'd like, you can use VS2013's feedback tool to submit a bug. A decent workaround would be to clean and rebuild your project before running it. Cleaning the bin and obj folders is a step up from that. There's a [PowerShell command](http://stackoverflow.com/a/5924807/612512) floating around to speed this up. – Christopher Stevenson Aug 03 '14 at 04:33

0 Answers0