MVC 4: Multiple Controller action parameters

asp.net-mvc, asp.net-mvc-routing

Solution

You will just need to map the new route in your global.asax, like this:

routes.MapRoute(
    "NewRoute", // Route name
    "{controller}/{action}/{id}/{another_id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional, another_id = UrlParameter.Optional } // Parameter defaults
);

Then in your controller's action you can pick up the parameter like this:

public ActionResult MyAction(string id, string another_id)
{
    // ...
}

Problem

Instead of just `{controller}/{action}/{id}` is it possible to have mulitple parameters like `{controller}/{action}/{id}/{another id}`? I'm new to MVC (coming from just plain Web Pages). If not possible, does MVC provide a helper method like the `UrlData` availble in Web Pages?

Original source