2013-04-17 62 views
0

我有這樣的動作鏈接:查詢字符串不正確地傳遞給操作鏈接

@Html.ActionLink("Export to Excel", // link text 
    "Export",      // action 
    "Members",      // controller 
    Request.QueryString,    // query string 
    "excel");      // class 

用我自己的重載操作鏈接方法:

public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, 
    string linkText, string action, string controllerName, 
    NameValueCollection queryString, string className) 
{ 
    var newRoute = new RouteValueDictionary(); 

    IDictionary<string, object> htmlAttributes = 
     new Dictionary<string, object> {{"class", className}}; 

    newRoute = htmlHelper.ViewContext.HttpContext.Request.QueryString.ToRouteDic(newRoute); 

    return HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, 
     htmlHelper.RouteCollection, linkText, null, action, null, 
     newRoute, htmlAttributes).ToMvcHtml(); 
} 

因此,這是頁面上的我的網址:

mysite.com/Members?searchName= & searchEmail = & agencyId = & agencyTypeId = & regionId = & regionId = 67 & searchTaxIdNum = & searchDateStart = & searchDateEnd =

和動作鏈接我生成此網址:

mysite.com/Members/Export?regionId =%2C67

所以出於某種原因%2C是越來越添加到regionId,但我沒有當然。任何人都知道我在做什麼錯了?

回答

2

%2在一個URL中相當於一個空格,你的代碼中可能有一個空白的地方。

相關問題