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.
1 Answer 1
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.
answered Sep 27, 2016 at 21:44
Shyju
220k106 gold badges421 silver badges499 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Shyju
To get the behavior you are after (having an id value with `` in it) ,you need to keep that as the last param
lang-cs