Html.ActionLink()를 사용하여 링크를 만듭니다. URL에서 얻은 쿼리 문자열의 조건에 따라 url에 매개 변수 문자열을 추가합니다. Concat string in Html.ActionLink()
<%
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)%>
<% }%>
이
내가 할 노력 무엇을 : 나는 문자열이 준비 CONCAT 후<%
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_add=aa=strA"
입니다.
아무에게도 더 나은 해결책을 보여줄 수 있습니까?
고마워요.
감사 짐. 어쨌든이 코드 블록을 Global.asax.cs에 넣어야합니까? – titi
titi -이 작은 블록은 strA 변수 등을 정의하는 기존 코드에 추가 될 수 있습니다. –
jim, {% : Html.ActionLink ("My link", "my_action", "my_controller", new {newRoutes}, null) %>',하지만 url은'blahblah.com/My_controller/My_action? newRoutes = System.Web.Routing.RouteValueDictionary'입니다. – titi