我正在使用asp.net mvc 3.我的项目中有三个区域,如
MyProject/Areas/Blogs
MyProject/Areas/Forums
MyProject/Areas/Groups
在这三者中,博客视图是启动视图。因为我已将globla.ascx设置为
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Blog", action = "Blog", id = UrlParameter.Optional }
);
并在BlogAreaRegistration.cs中,
context.MapRoute(
"Blogarea_Default",
"{controller}/{action}/{id}",
new { controller = "Blog", action = "Blog", id = UrlParameter.Optional }
);
并在ForumAreaRegistration.cs中,
context.MapRoute(
null,
"Forums/{action}/{id}",
new {controller="Forums", action = "Forum", id = UrlParameter.Optional }
);
并在GroupsAreaRegisration.cs中,
context.MapRoute(
"Groups_default",
"Groups/{controller}/{action}/{id}",
new { controller = "Groups", action = "Group", id = UrlParameter.Optional }
);
此处论坛和博客正如我所愿,但该集团无法正常工作它始终显示 404资源未找到页面所以如果我在此过程中有任何错误,请指导我。
答案 0 :(得分:2)
尝试更改
context.MapRoute(
"Groups_default",
"Groups/{controller}/{action}/{id}",
new { controller = "Groups", action = "Group", id = UrlParameter.Optional }
);
有:
context.MapRoute(
"Groups_default",
"Groups/{action}/{id}",
new { controller = "Groups", action = "Group", id = UrlParameter.Optional }
);
答案 1 :(得分:0)
您应该从Groups/
代码块中删除{controller}/
或GroupsAreaRegisration.cs
- 然后它应该有效。我删除了{controller}/
,因此代码将为:
context.MapRoute(
"Groups_default",
"Groups/{action}/{id}",
new { controller = "Groups", action = "Group", id = UrlParameter.Optional }
);
同样在BlogAreaRegistration.cs
我将{controller}
替换为Blog
,否则您可能会得到意想不到的结果。这里的完整代码将是
context.MapRoute(
"Blogarea_Default",
"Blog/{action}/{id}",
new { controller = "Blog", action = "Blog", id = UrlParameter.Optional }
);