MVC 4 Areas not working properly

亡梦爱人 提交于 2019-12-14 03:58:06

问题


I have created a sample VB project in VS2010 to add Areas to the web UI but when I run it gives the following error:

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

I also added AreaRegistration.RegisterAllAreas() to the global.asax file and also tried to manually register the route in the route.config but nothing is working.

routes.MapRoute( _
            "Admin_default", _
            "Admin/{controller}/{action}/{id}", _
            New With {.action = "Index", .id = UrlParameter.Optional} _
            )

It looks like it only finds the root views but not the Area specific view. Any ideas??


回答1:


Found an answer on another site so posting the solution here:

The same project in C# works perfectly fine but fails in VB. The reason: The controllers namespace is wrong in VB.net Solution: Change the namespace of the controller in the vb project to MyApplication.Areas.MyArea.Controllers and then run it, will be fine.




回答2:


Make sure you add AreaRegistration.RegisterAllAreas() as first line in Global.asax. Because areas should be registered before registering other routes.

Also in the route you mentioned, there is no default value for controller. So, make sure you provide controller value in url or provide default controller parameter in route.



来源:https://stackoverflow.com/questions/25391355/mvc-4-areas-not-working-properly

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