MVC 3区路线不工作

编程入门 行业动态 更新时间:2024-10-07 16:19:24
本文介绍了MVC 3区路线不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在所谓的'博客'MVC 3应用程序创建一个区域。

I created a Area in my MVC 3 application called 'Blog'.

在Global.asax中,我有以下code。

In global.asax I have the following code.

public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); } protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); }

这是我区的code

public class BlogAreaRegistration : AreaRegistration { public override string AreaName { get { return "Blog"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Blog_default", "Blog/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } ); } }

当我去到以下网址的http://本地主机/ CMS /博客我收到以下错误

When I go to the following url localhost/CMS/blog I get the following error.

视图索引或它的主人没有被发现或没有视图引擎支持搜索位置。在以下地点被搜查:  〜/查看/博客/的Index.aspx  〜/查看/博客/ Index.ascx  〜/查看/共享/的Index.aspx  〜/查看/共享/ Index.ascx  〜/查看/博客/ Index.cshtml  〜/查看/博客/ Index.vbhtml  〜/查看/共享/ Index.cshtml  〜/查看/共享/ Index.vbhtml

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/blog/Index.aspx ~/Views/blog/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx ~/Views/blog/Index.cshtml ~/Views/blog/Index.vbhtml ~/Views/Shared/Index.cshtml ~/Views/Shared/Index.vbhtml

我该如何解决这个问题?

How do I solve this?

推荐答案

在您所在地区的注册看来是错误的。您可以指定你的行动而不是控制器默认值。既然你通常有家庭作为控制器的名称你需要指定。

The registration in your area appears to be wrong. You specify a default for your action but not for the controller. Since you typically have Home as the name of the controller you'd need to specify that.

此外,它可能是你没有正确拥有文件夹的设置,因为你应该有物理设置:

Also it could be you don't have your folders setup correctly since you should have physically setup:

  • /地区/博客
  • /地区/博客/控制器
  • /地区/博客/浏览次数

......,一旦你有固定你的博客区的路线,你还需要:

... and once you have fixed your blog area route you'll also need:

  • /地区/博客/浏览/家居与LT;<把你的索引视图在这里

您得到的错误似乎pretty清楚地表明这是问题。

The error you get seems to pretty clearly indicate this is the issue.

更多推荐

MVC 3区路线不工作

本文发布于:2023-11-25 21:36:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路线   工作   MVC

发布评论

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

>www.elefans.com

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