I\'d like to send multiple parameters to an action in ASP.NET MVC. I\'d also like the URL to look like this:
http://example.com/products/item/2
If you want a pretty URL, then add the following to your global.asax.cs
.
routes.MapRoute("ProductIDs",
"Products/item/{id}",
new { controller = Products, action = showItem, id="" }
new { id = @"\d+" }
);
routes.MapRoute("ProductIDWithSender",
"Products/item/{sender}/{id}/",
new { controller = Products, action = showItem, id="" sender="" }
new { id = @"\d+", sender=@"[0-9]" } //constraint
);
And then to use the needed actions:
public ActionResult showItem(int id)
{
//view stuff here.
}
public ActionResult showItem(int id, int sender)
{
//view stuff here
}