不在区域文件夹中搜索视图(Not searching for view in Areas folder)

编程入门 行业动态 更新时间:2024-10-24 20:13:59
不在区域文件夹中搜索视图(Not searching for view in Areas folder)

我是新手,所以如果我错过了一些相关的细节,请原谅我。

我试图点击一个名为“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 } ); }

有任何想法吗?

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.vbhtml

I 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.cs

EventAreaRegistration 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" } ); } }

更多推荐

本文发布于:2023-07-27 05:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1285493.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   区域   文件   夹中   folder

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!