1

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.

asked Sep 27, 2016 at 19:58

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

To get the behavior you are after (having an id value with `` in it) ,you need to keep that as the last param

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.