2010-03-12 22 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(); } 
}