2010-03-12 53 views
4

使用ASP.NET MVC,我需要配置這樣我的網址:如何在ASP.NET MVC中配置3個級別的URL?

www.foo.com/company:渲染視圖公司

www.foo.com/company/about:渲染查看公司

www.foo.com/company/about/mission:渲染視圖任務

如果「公司」是我的控制器和「約」是我的行動,應該是什麼「MI裂變「?

對於每個「文件夾」(公司,關於和任務),我必須呈現不同的視圖。

任何人都知道我該怎麼做?

謝謝!

回答

4

首先,設置你的意見:

Views\ 
    Company\ 
    Index.aspx 
    About.aspx 
    Mission.aspx 
    AnotherAction.aspx 

在你GlobalAsax.RegisterRoutes(RouteCollection路線)方法:

public static void RegisterRoutes(RouteCollection routes) 
{ 
    // this will match urls starting with company/about, and then will call the particular 
    // action (if it exists) 
    routes.MapRoute("mission", "company/about/{action}", 
     new { controller = "Company"}); 
    // the default route goes at the end... 
    routes.MapRoute(
    "Default",            // Route name 
    "{controller}/{action}/{id}",       // URL with parameters 
    new { controller = "Home", action = "Index", id = "" } // Parameter defaults 
); 
} 

在控制器:

CompanyController 
{ 
    public ViewResult Index() { return View(); } 
    public ViewResult About() { return View(); } 
    public ViewResult Mission() { return View(); } 
    public ViewResult AnotherAction() { return View(); } 
}