How to avoid query string parameters in MVC

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, when I call RedirectToAction, the url is displayed as

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

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

I would like

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

How do I achieve this?

+3
source share
1 answer

I assume the call RedirectToActionselects the default route, not your specialized route.

By default, when you pass route values, MVC will add values ​​as query parameters.

Have you sent this route to the default route?

+3

Source: https://habr.com/ru/post/1779713/


All Articles