Razor View Engine is not looking for a field of view

I use the default RazorViewEngine setting and the area layout configuration, however, when I am on a link that uses a view within the area. I get an error "Cannot find and search" in the following places:

~/Views/Applications/Details.cshtml ~/Views/Applications/Details.vbhtml ~/Views/Shared/Details.cshtml ~/Views/Shared/Details.vbhtml 

What I find strange is that it looks like the view engine is not trying to find a location in the area. What adjustments should I make to get the view engine to view the views in my area.

Here is the related code that I used to determine my area.

Global.asax.cs

 protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteRegistrar.RegisterRoutesTo(RouteTable.Routes); } 

ApplicationAreaRegistration.cs

 private void RegisterRoutesTo(RouteCollection routes) { routes.MapRoute("Application_default", AreaName + "/{action}/{applicationId}", new { controller = "Applications", action = "Index", applicationDomainId = UrlParameter.Optional }, new { applicationId = @"\d+" }); } 

Index.cshtml

 @Html.RouteLink(item.Name, "Application_default", new { applicationId = item.Id, action = "Details" }) 

Physical Directory Layout

 Areas \ \Application \Controllers -ApplicationsController.cs \Views -Details.cshtml -ApplicationAreaRegistration.cs 
+4
source share
2 answers

Are you sure RegisterRoutesTo() is being called in ApplicationAreaRegistration.cs ? It seems that the route to your region is not registered.

I would suggest moving MapRoute back to the RegisterArea override in ApplicationAreaRegistration.cs .

+3
source

Your MapRoute seems like a problem. Try adding an area ad.

 routes.MapRoute("Application_default", AreaName + "/{action}/{applicationId}", new { area= "Application", controller = "Applications", action = "Index", applicationDomainId = UrlParameter.Optional }, new { applicationId = @"\d+" }); 

Alternatively, just double-check the various overloads available for Html.RouteLink - you might want to add a scope to the RouteValues collection

 `new {area="Application", applicationId = item.Id, action = "Details"}` 

when using RouteLink outside the field

0
source

All Articles