0

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.

Theodoros Chatzigiannakis
  • 28,773
  • 8
  • 68
  • 104

1 Answers1

1

There are several techniques for doing this, however, none of them is fully automatic, you still have to tell the ActionLink explicitly what you want inside the actionlink.

There are a few questions on stackoverflow that describe the same or a similar problem which you could check out:

Community
  • 1
  • 1
Kenneth
  • 28,294
  • 6
  • 61
  • 84