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 });
3
  • 1
    Your Answer might be here: stackoverflow.com/questions/33344450/… Commented Mar 14, 2017 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 Commented Mar 14, 2017 at 14:40
  • @DiegoAlves add that as the answer to your question so that others can benefit from it in the future. Commented Mar 14, 2017 at 15:01

0

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.