Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RedirectToAction without querystring MVC

Tags:

asp.net-mvc

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=the-farm-name

What i'd like it to do is this

/Farm/Details/the-farm-name

Is there a simple way to do this?

like image 393
James South Avatar asked Mar 17 '11 08:03

James South


2 Answers

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

like image 83
Furqan Hameedi Avatar answered Nov 11 '22 15:11

Furqan Hameedi


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.

like image 1
Gengzu Avatar answered Nov 11 '22 15:11

Gengzu