ASP.NET MVC路由和地区 [英] ASP.NET MVC routing and areas
问题描述
我与ASP.NET MVC 2 preVIEW 2瞎搞,我试图找出路由如何与地区和这样的。在单个项目的实施方面,我想叫一个区域管理员。
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".
我想能有这样的网址:
(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.
谢谢!
除了这个问题(2009/10/25)
我基本上问我会在该地区的AreaRegistration类设置什么样的路线和以什么顺序呢?我已经做了迄今为止提到的一切,但没有结果。
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.
推荐答案
<一个href=\"http://msdn.microsoft.com/en-us/library/ee461420%28VS.100%29.aspx#registering%5Farea%5Froutes\">Register在单项目领域
您必须添加routes.cs文件到管理区的文件夹。
You have to add routes.cs file to the admin area folder.
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 = "" }
);
}
}
}
这篇关于ASP.NET MVC路由和地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!