3

I have the following route

routes.MapRoute("CreateBook", "{controller}/{action}/{slug}/{name}", new { controller = "CreateBook", action = "Index" , slug = UrlParameter.Optional, name = UrlParameter.Optional});

For some reason, whenever I call RedirectToAction, the URL appears as

return RedirectToAction("Parameters", new { slug=1234, name="helloworld" });

http://localhost/CreateBook/Parameters?slug=1234?name=helloworld

What I would like is

http://localhost/CreateBook/Parameters/1234/helloworld

How do I achieve this?

1 Answer 1

3

My guess is that the RedirectToAction call is picking up the default route, not your specialised route.

By default, when you pass in route values, MVC will append the values as querystring parameters.

Did you put that route before the default route?

Sign up to request clarification or add additional context in comments.

1 Comment

@Sir Psycho - hehe, thought so. If you haven't already, grab Phil Haack's "Route Debugger". Will save you LOTS of route debugging time.

Your Answer

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.