Reputation: 13594
Currently I have a Controller named StoreController. There are three Categories : books, movies, and games. How can i make sure that the url's
match a single action method. Right now, I am having three separate action methods books(); movies(); games();
doing the same thing, i.e listing the products in them
Upvotes: 0
Views: 507
Reputation: 8804
Did you try like this?
routes.MapRoute(
"Default", // Route name
"{controller}/{id}", // URL with parameters
new { controller = "Store", action = "Index", id = UrlParameter.Optional } // Parameter defaults
, null }
)
and you make Controller like
public ActionResult Index(string id)
{
if(id == "books"){
}
else if(id == "movies"){
}
else{// this is null case
}
return Content("hello");// test
}
Upvotes: 3