By default, the MVC3 route to the area does not look for an internal view.

I set the default route object to the controller ("Beheer") inside the area (also called "Beheer").

Like this:

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

He can find this controller and action within the scope, but he cannot find the view, because it only looks in these places:

 ~/Views/Beheer/Index.aspx ~/Views/Beheer/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx ~/Views/Beheer/Index.cshtml ~/Views/Beheer/Index.vbhtml ~/Views/Shared/Index.cshtml ~/Views/Shared/Index.vbhtml 

While it should look in this place:

 ~/Beheer/Views/Beheer/Index.aspx 

How can I make him search there?

I already tried:

 routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { area = "Beheer", controller = "Beheer", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); 

And I tried this (with namespaces):

  routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Beheer", action = "Index", id = UrlParameter.Optional }, // Parameter defaults new[] { "Areas.Beheer" } ); 

But nothing changes. It introduces the correct action in the correct controller, but cannot find a representation.

+4
source share
2 answers

You must add your route to the check-in area. BeheerAreaRegistration has a property that sets the scope name.

 public class BeheerAreaRegistration : AreaRegistration { public override string AreaName { get { return "Beheer"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Beheer", action = "Index", id = UrlParameter.Optional } // Parameter defaults); } 
+2
source

I had this problem and I found that I need to fully qualify the namespaces, and I have problems finding it the right way until I destroy the IIS process, some weird caching, or something else.

 new[] { "Areas.Beheer" } 

can be

 new[] {"myApp.Areas.Beheer.Controllers"} 

Perhaps your problem is similar to mine - perhaps not.

0
source

Source: https://habr.com/ru/post/1386517/


All Articles