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

 ̄綄美尐妖づ 提交于 2019-12-07 02:21:36

问题


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.


回答1:


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.




回答2:


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

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




回答3:


I'm guessing you using cassini (builtin dev web server in VS.Net)? If so I get this all the time and seams to be a bug in VS.Net. Switch to IIS 7.5 and you don't get it any more



来源:https://stackoverflow.com/questions/8851641/mvc-3-tries-to-launch-url-to-view-instead-of-controller-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!