Home > DeveloperSection > Forums > How to use first querystring parameter and append to action in url in asp.net mvc 4?
jayprakash sharma
jayprakash sharma

Total Post:117

Posted on    November-13-2014 10:53 PM

 ASP.NET MVC C#  ASP.Net  Url Routing  Routing 

 1 Reply(s)
 742  View(s)
Rate this:

I'd like to tidy this url if at all possible.

Curently it looks like this which is returned from an ActionResult GET


Here's what I'm trying to achieve


The City parameter isn't used for anything, so manually editing the first url into the second does indeed return the correct data.

I've even tried appending int the City variable to the action, not really ideal.




                new { controller = "House", action = "Location", City = UrlParameter.Optional }


Pravesh Singh
Pravesh Singh

Total Post:101

Posted on    November-14-2014 2:16 AM

You were almost there with the routing change. Add this code BEFORE the default route




    new { controller = "House", action = "Location" }


Note that I change the url format slightly and removed the optional parameter part (it's not needed)

Don't want to miss updates? Please click the below button!

Follow MindStick