我是新手,如果我错过了一些相关的细节,请原谅我。
我正在尝试点击一个名为“Birthday”的页面,其中有一个视图“Birthday.cshtml”。我的网址看起来像http://example.com/en-us/Event/Birthday
。当我尝试转到网址时,浏览器会显示此错误:
The view 'Birthday' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Event/Birthday.aspx
~/Views/Event/Birthday.ascx
~/Views/Shared/Birthday.aspx
~/Views/Shared/Birthday.ascx
~/Views/Event/Birthday.cshtml
~/Views/Event/Birthday.vbhtml
~/Views/Shared/Birthday.cshtml
~/Views/Shared/Birthday.vbhtml
我不能为我的生活弄清楚为什么它不在~/Areas/Event/Views/Birthday.cshtml
位置。
我的文件夹结构如下:
Areas
\ Event
\ Controllers
- EventController.cs
\ Models
\ Views
- Birthday.cshtml
- EventAreaRegistration.cs
EventAreaRegistration看起来像这样:
public class EventAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Event";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Event_default",
"Event/{action}/{id}",
new { controller = "Event", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "ProjectName.Areas.Event.Controllers" }
);
}
}
Global.asax.cs包括以下几行:
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
RegisterRoutes看起来像这样:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{locale}/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", locale = Locale.defaultLocale, id = UrlParameter.Optional }
);
}
有什么想法吗?
答案 0 :(得分:0)
想出来。 EventAreaRegistration.cs MapRoute()函数中缺少URL的{locale}部分,因此该路由实际上并未使用。
public class EventAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Event";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Event_default",
"{locale}/Event/{action}/{id}",
new { controller = "Event", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "ProjectName.Areas.Event.Controllers" }
);
}
}
答案 1 :(得分:0)
Change it to
public class EventAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Event";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Event_default",
"Event/{controller }/{action}/{id}", //change here add controller
new { controller = "Event", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "ProjectName.Areas.Event.Controllers" }
);
}
}