Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My solution is similar to qwerty1000's. I created an extension method, <code>ActionQueryLink</code>, that takes in the same basic parameters as the standard <code>ActionLink</code>. It loops through Request.QueryString and adds any parameters found to the <code>RouteValues</code> dictionary that are not already present (so we can overwrite the original query string if needed).</p> <p>To preserve the existing string but not add any keys the usage would be:</p> <pre><code>&lt;%= Html.ActionQueryLink("Click Me!","SomeAction") %&gt; </code></pre> <p>To preserve the existing string and add new keys the user would be:</p> <pre><code>&lt;%= Html.ActionQueryLink("Click Me!","SomeAction", new{Param1="value1", Param2="value2"} %&gt; </code></pre> <p>The code below is for the two usages, but it should be pretty easy to add other overloads to match the other <code>ActionLink</code> extensions as needed.</p> <pre><code> public static string ActionQueryLink(this HtmlHelper htmlHelper, string linkText, string action) { return ActionQueryLink(htmlHelper, linkText, action, null); } public static string ActionQueryLink(this HtmlHelper htmlHelper, string linkText, string action, object routeValues) { var queryString = htmlHelper.ViewContext.HttpContext.Request.QueryString; var newRoute = routeValues == null ? htmlHelper.ViewContext.RouteData.Values : new RouteValueDictionary(routeValues); foreach (string key in queryString.Keys) { if (!newRoute.ContainsKey(key)) newRoute.Add(key, queryString[key]); } return HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, null /* routeName */, action, null, newRoute, null); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload