views:

69

answers:

1

Using ASP.NET MVC, I need to configure my URLs like this:

www.foo.com/company : render View Company

www.foo.com/company/about : render View Company

www.foo.com/company/about/mission : render View Mission

If "company" is my controller and "about" is my action, what should be "mission"?

For every "folder" (company, about and mission) I have to render a different View.

Anyone knows how can I do that?

Thanks!

+3  A: 

First, setup your views:

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

In your GlobalAsax.RegisterRoutes(RouteCollection routes) method:

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
  );
}

In the controller:

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