5

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!

1 Answer 1

4

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(); }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.