Reputation: 45
I am creating a MVC 4 application and using the route mapping to route a url like http://ModelSearch.com/Home/PartDetail/1000-1583-XIR/a
routes.MapRoute("PartDetail", "{controller}/{action}/{id}/{rev}", new { action = "PartDetail" });
There might be id like "1000/1584"
http://ModelSearch.com/Home/PartDetail/1000/1584/b
How do I handle it from new mapRoute? wildcard doesn't work for middle parameter.
Upvotes: 1
Views: 1226
Reputation: 218732
You can re arrange your parameter and use the wildcard url segments for Id at the end of your url pattern.
[Route("Home/PartDetail/{rev}/{*id}")]
public ActionResult PartDetail(string rev,string id)
{
return Content("rev:"+rev+",id:"+id);
}
The *id
is like a catch anything. So "1000/1584"
segment of the request url will be mapped to the id
parameter.
Upvotes: 2