我是新手,所以如果我错过了一些相关的细节,请原谅我。
我试图点击一个名为“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.csEventAreaRegistration看起来像这样:
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 } ); }有任何想法吗?
I'm new to areas, so forgive me if I miss some relevant details.
I am trying to hit a page called "Birthday" for which there is a view "Birthday.cshtml". My url looks like http://example.com/en-us/Event/Birthday. When I attempt to go to the url, the browser shows me this error:
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.vbhtmlI cannot for the life of me figure out why it is not looking in the ~/Areas/Event/Views/Birthday.cshtml location.
My folder structure is as follows:
Areas \ Event \ Controllers - EventController.cs \ Models \ Views - Birthday.cshtml - EventAreaRegistration.csEventAreaRegistration looks like this:
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 includes these lines:
AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes);RegisterRoutes looks like this:
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 } ); }Any ideas?
最满意答案
弄清楚了。 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" } ); } }Figured it out. The {locale} part of the URL was missing from the EventAreaRegistration.cs MapRoute() function, so that route wasn't actually being used.
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" } ); } }更多推荐
发布评论