Removing null/empty keys from a query string in asp.net MVC
asp.net, asp.net-mvc, query-string, routes, url-routing
Solution
How are you generating that URL? With Routing, if those are meant to be in the query string, it should work fine. We only generate query string parameters for RouteValues that you specify.
One thing I've done in the past is to write my own helper method for specific links where I might pass in an object for route values, but want to clear out the values that I don't need before passing it to the underlying routing API. That worked well for me.
Problem
Is there a way I can remove null or empty keys from a query string in asp.net MVC? For example I have a page where I filter data on a results table, if I search for John the query string would be redisplayed as: ``` candidates?FirstName=John&LastName=&Credit=false&Previous=false&Education=&Progress= ``` and not ``` candidates?FirstName=John ``` I looked at URL routing but I wasn't sure if it was something that should be used for cosmetic things like this or if it is possible to achieve what I'm asking using it.