I am messing around with ASP.NET MVC 2 Preview 2 and am trying to figure out how routing works with areas and such. In a single project implementation of areas, I want an area named "admin".
我正在搞乱ASP.NET MVC 2 Preview 2,并试图弄清楚路由如何与区域等一起工作。在区域的单个项目实施中,我想要一个名为“admin”的区域。
I am trying to be able to have urls like this:
我想要能够拥有这样的网址:
(root)/admin/apples/search
(root)/admin/apples/edit/3
(root)/admin/apples/add
(root)/admin/oranges/search
(root)/admin/oranges/edit/5
(root)/admin/oranges/add
(root)/admin
I have the area created. I have the controllers created with their respective views, but it is the routing that I can't seem to get. Any advice as to how I would achieve such routing?
我创建了该区域。我用各自的视图创建了控制器,但这是我似乎无法获得的路由。关于如何实现这种路由的任何建议?
I am sure this may be extremely simple for some, but I haven't had too much luck in finding examples that go beyond the basic stuff.
我相信这对某些人来说可能非常简单,但我没有太多运气找到超越基本内容的例子。
Thanks!
谢谢!
Addition to the Question (10/25/2009) I am basically asking what routes and in what order would I set up in the Area's AreaRegistration class? I have done everything mentioned so far, but with no results.
问题的补充(10/25/2009)我基本上是在问区域区域注册课程中设置的路线和顺序是什么?到目前为止,我已经做了所有提到的事情,但没有结果。
2 个解决方案
#1
27
Register areas in single project
在单个项目中注册区域
You have to add routes.cs file to the admin area folder.
您必须将routes.cs文件添加到管理区域文件夹。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcAreasSingleProject.Areas.Admin
{
public class Routes : AreaRegistration
{
public override string AreaName
{
get { return "admin"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"admin_default",
"admin/{controller}/{action}/{id}",
new { controller = "Admin", action = "Edit", id = "" }
);
}
}
}
#2
0
http://haacked.com/archive/2009/07/31/single-project-areas.aspx
http://haacked.com/archive/2009/07/31/single-project-areas.aspx
routes.MapAreaRoute("Forums", "admin_area", "admin/{controller}/{action}/{id}", new { controller = "apples", action = "search", id = "" }, new string[] { "Project.Areas.Admin.Controllers" });
#1
27
Register areas in single project
在单个项目中注册区域
You have to add routes.cs file to the admin area folder.
您必须将routes.cs文件添加到管理区域文件夹。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcAreasSingleProject.Areas.Admin
{
public class Routes : AreaRegistration
{
public override string AreaName
{
get { return "admin"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"admin_default",
"admin/{controller}/{action}/{id}",
new { controller = "Admin", action = "Edit", id = "" }
);
}
}
}
#2
0
http://haacked.com/archive/2009/07/31/single-project-areas.aspx
http://haacked.com/archive/2009/07/31/single-project-areas.aspx
routes.MapAreaRoute("Forums", "admin_area", "admin/{controller}/{action}/{id}", new { controller = "apples", action = "search", id = "" }, new string[] { "Project.Areas.Admin.Controllers" });