我将默认路由对象设置为区域内的控制器(“Beheer”)(也称为“Beheer”).
像这样:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Beheer", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
它可以在区域内找到控制器和动作,但它找不到视图,因为它只查看这些位置:
~/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
虽然它应该在这个位置寻找:
~/Beheer/Views/Beheer/Index.aspx
如何让它在那里搜索视图?
我已经尝试过:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { area = "Beheer", controller = "Beheer", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
我尝试了这个(使用名称空间):
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Beheer", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { "Areas.Beheer" }
);
但没有变化.它在正确的控制器中输入正确的操作但无法找到视图.
最佳答案 您应该在区域注册中添加您的路线. BeheerAreaRegistration具有设置区域名称的属性.
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);
}