Add parameter to initialize existing asp.net mvc url

I am using asp.net mvc. FROM#

How can I get an existing url (there could be a bunch of querystring parameters on it) and then just add another parameter to quesrystring. and make it an interactive hyperlink.

+5
source share
1 answer

You will need to create a custom variable RouteValueDictionaryto go to Html.ActionLink. Try something like this:

<% 
     var rvd = new RouteValueDictionary(ViewContext.RouteData.Values);
     foreach (string key in Request.QueryString.Keys )
     {
         rvd[key]=Request.QueryString[key];
     } 
     rvd["MyParam"] = "WhateverValue";
     Response.Write(Html.ActionLink("Link Text", "Action", rvd));
%>
+4
source

All Articles