0

My url is being displayed something like this: http:\mydomain.com.br\Cars\Search\23

the Cars is my controller, Search is my action and 23 is route parameter. I am not happy with this url mainly because of the uppercase letters. I would like to change it to http:\mydomain.com.br\result_car_search\23. I want to change the url without changing the structures of my controllers/actions.

I've using this to generate the "ugly" url.

@Html.ActionLink("Volkswagem Gol", "Search", "Car", new  { param = 93}, null)

I've tried to use

 @Html.RouteLink("Fiat Palio", "result_car_search", new { param = 30}, null)

but for my surprise it generage a url pointing to the current url with the route parameter appended to the end.

my route is this:

routes.MapRoute("result_car_search", "{controller}/{action}/{param}", new { controller = "Car", action = "Search", param= UrlParameter.Optional });
Diego Alves
  • 2,462
  • 3
  • 32
  • 65
  • 1
    Your Answer might be here: http://stackoverflow.com/questions/33344450/how-to-change-asp-net-mvc-controller-name-in-url – Minhaj Hussain Mar 14 '17 at 14:13
  • 1
    Your comment helped! That's what I wanted: change the controller and action names in the url. But I knew from the beginning that it doesn't require changes in the controller. I searched google for "change the controlller name in asp.net mvc url" and I found the solution. I can define a route like this: routes.MapRoute("result_car_search", "whatever_I_want", new { controller = "Car", action = "Search", param= UrlParameter.Optional }) and get this : domain\whatever_I_want\23 – Diego Alves Mar 14 '17 at 14:40
  • @DiegoAlves add that as the answer to your question so that others can benefit from it in the future. – Nkosi Mar 14 '17 at 15:01

0 Answers0