将参数附加到现有url asp.net mvc的查询字符串

rak*_*los 5 c# asp.net-mvc

我使用asp.net mvc.C#

我如何获得现有的url(可能有一堆查询字符串参数)然后只是将另一个参数附加到quesrystring.并使其成为可点击的超链接.

wom*_*omp 6

您将需要构建一个自定义RouteValueDictionary变量以传递给Html.ActionLink.尝试这样的事情:

<% 
     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));
%>
Run Code Online (Sandbox Code Playgroud)