I have a view responding to the action /Page/Index/{id}
(default ASP.NET MVC routing). The view contains action links that lead to the same action with the same id
but with an added parameter in the URL. I've put something like this in place:
@Html.ActionLink("SetVar1", "Index", new { var1 = "true" } )
@Html.ActionLink("SetVar2", "Index", new { var2 = "true" } )
As expected, clicking on one of those links redirects me to the same action with the same id
and with a parameter.
Page/Index/{id}?var1=true
The user is then presented with the above links again. Of course, if the user clicks again on another action link, only the new parameter is there.
Page/Index/{id}?var2=true
What I want instead is to make the action links retain all the previously passed parameters and add a new one (or replace it if it already has a value in the request).
Page/Index/{id}?var1=true&var2=true
How can I do that?
It is crucial that I don't hardcode all the possible parameter names and I'd also find it very inelegant to do string manipulation to the URL directly. I should also note that the parameters are completely independent of each other.