查询字符串未正确传递给Action Link

时间:2013-04-17 01:59:03

标签: c# asp.net asp.net-mvc

我有这个动作链接:

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

使用我自己重载的Action Link方法:

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,但我不确定。谁知道我做错了什么?

1 个答案:

答案 0 :(得分:2)

URL中的

%2相当于一个空格,您的代码中可能有一个空格。