newUser
newUser

Reputation: 21

MVC 4 Areas not working properly

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??

Upvotes: 1

Views: 642

Answers (2)

newUser
newUser

Reputation: 21

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.

Upvotes: 1

Vikram Babu Nagineni
Vikram Babu Nagineni

Reputation: 3549

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.

Upvotes: 0

Related Questions