MVC 3区路线不工作 [英] MVC 3 Area route not working
问题描述
我在所谓的'博客'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 http://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区路线不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!