Asp.net Html.ActionLink()中的Concat字符串

Asp.net Html.ActionLink()中的Concat字符串,asp.net,asp.net-mvc,asp.net-mvc-2,Asp.net,Asp.net Mvc,Asp.net Mvc 2,我使用Html.ActionLink()创建了一个链接。我根据从url获取的查询字符串的条件向url添加参数字符串 <% strA = Request.QueryString["AA"]; strB = Request.QueryString["BB"]; strC = Request.QueryString["CC"]; if (!string.IsNullOrEmpty(strA)) { %> <%: Html.ActionLink(a.Name, Model.A

我使用Html.ActionLink()创建了一个链接。我根据从url获取的查询字符串的条件向url添加参数字符串

<% 
strA = Request.QueryString["AA"];
strB = Request.QueryString["BB"];
strC = Request.QueryString["CC"];

if (!string.IsNullOrEmpty(strA))
{
%>
   <%: Html.ActionLink(a.Name, Model.ActionName, Model.ControllerName, 
       new {aa = strA , tab = 2}, null)%>
<%
}else if(!string.IsNullOrEmpty(strB)){
%>
   <%: Html.ActionLink(a.Name, Model.ActionName, Model.ControllerName, 
       new {bb = strB , tab = 2}, null)%>
<%
}else if(!string.IsNullOrEmpty(strA) &&  !string.IsNullOrEmpty(strB)){
%>
   <%: Html.ActionLink(a.Name, Model.ActionName, Model.ControllerName, 
       new {aa = strA , bb = strB, tab = 2}, null)%>
<%else{ %>
   <%: Html.ActionLink(a.Name, Model.ActionName, Model.ControllerName, 
       new {tab = 2}, null)%>
<% }%>

这就是我试图做的:

 <%
 string url_add =  "";
 if (!string.IsNullOrEmpty(strA))
 {  
  url_add += "aa=strA";
 }else if(!string.IsNullOrEmpty(strB)){
  url_add += "bb=strB";
 }else if(!string.IsNullOrEmpty(strA) &&  !string.IsNullOrEmpty(strB)){
  url_add += "aa=strA&bb=strB";
 }else{
  url_add += "tab=2";
 }
 %>

在我准备好字符串后,我将该字符串放在如下位置:

<%: Html.ActionLink("My link", "my_action", "my_controller", new {url_add} , null) %>

但当我这样做时,我的url将
“blahblah.com/url\u add=aa=strA”

谁能告诉我更好的解决办法吗

非常感谢。

提提

问题与您试图将单个属性“对象”添加到routevalues字典有关,即:

<%: Html.ActionLink("My link", "my_action", "my_controller", new {url_add} , null) %>
希望这能提供一些想法

[编辑]-为了回应您下面的评论,这里是您所需的重载,包括@class对象:

<%: Html.ActionLink("My link", "my_action", "my_controller", newRoutes, new Dictionary<string, object> { { "class", "selectedQ" } }) %>


谢谢,吉姆。无论如何,我必须将这段代码放在Global.asax.cs或where中吗?titi-这段代码可以添加到现有代码中,您可以在其中定义strA变量etcjim,我尝试添加链接
,但是url是
blahblah.com/My_controller/My_action?newRoutes=System.Web.Routing.RouteValueDictionary
。更新:现在它可以与
一起使用,但是我想添加这样的链接时遇到了一个问题:
<%: Html.ActionLink("My link", "my_action", "my_controller", newRoutes, new Dictionary<string, object> { { "class", "selectedQ" } }) %>