开发者

RedirectToAction without querystring MVC

开发者 https://www.devze.com 2023-02-17 04:17 出处:网络
I have a bit of code here in my mvc app that performs a redirect. return RedirectToAction(\"Details\", new { slug = viewModel.Farm.Slug });

I have a bit of code here in my mvc app that performs a redirect.

return RedirectToAction("Details", new { slug = viewModel.Farm.Slug });

This redirect to the url

/Farm/Details?slug=th开发者_开发知识库e-farm-name

What i'd like it to do is this

/Farm/Details/the-farm-name

Is there a simple way to do this?


Define a route matching to the above in the Routes Table in your global.asax.


you are using default routing, where you have defined one parameter "id". Change your code to return

RedirectToAction("Details", new {id = viewModel.Farm.Slug });

or add new route.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号