Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 tries to launch URL to View instead of controller action

Sometimes when I launch my MVC 3 project it attempts to load the fully qualified URL for the view being rendered instead of the action within the controller (Which gives me a 404 error). Other times it works fine and actually hits the controller action like it's supposed to, but it's about 50/50.

The URL it hits sometimes is: http://localhost:xxxx/Views/Account/LogOn.cshtml

Here is the default route setup in the Global.asax file:

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Account", action = "LogOn", id = UrlParameter.Optional } 
        );

I also tried removing the /{id} parameter from the route as I don't feel it's needed for the logon screen.

Any ideas? Currently the project is setup pretty simply with the default action method LogOn in the AccountController etc. The only thing I did was change the controller and action in the global.asax file.

like image 668
S9Designs Avatar asked Jan 13 '12 13:01

S9Designs


2 Answers

Try this :go to Project Properties > Web > Start Action

And check the Specific Page option - leaving the text box blank.

like image 114
codingbadger Avatar answered Sep 28 '22 13:09

codingbadger


You are probably using Visual Studio and you probably are actively editing a .cshtml page when you hit debug.

Try launching the debugger when you are either looking at a code file or a file from a project that isn't in the startup project (ie, your EF/model project) and see if that launches the debugger to the correct URL.

There might be a setting in the project properties that specifies the startup URL. I'll look for it and edit this post if I find it.

like image 31
joe_coolish Avatar answered Sep 28 '22 12:09

joe_coolish