Sas*_*sha 7 binding asp.net-mvc-routing url.action asp.net-mvc-3
我正在尝试将int []数组添加到我的Url.Action中,如下所示:
var routeData = new RouteValueDictionary();
for (int i = 0; i < Model.GroupsId.Length; i++) {
routeData.Add("GroupsId[" + i + "]", Model.GroupsId[i]);
}
Run Code Online (Sandbox Code Playgroud)
在我看来:
Url.Action("Index", routeData)
Run Code Online (Sandbox Code Playgroud)
但在html我得到:
GroupsId%5B0%5D=1213&GroupsId%5B0%5D=1214
Run Code Online (Sandbox Code Playgroud)
并不是:
GroupsId=1213&GroupsId=1214
Run Code Online (Sandbox Code Playgroud)
我需要它,因为我有一个复选框列表,当我发布时我将groupIds绑定到int [],然后传递给我查看我有导出按钮的地方,其中Url.Action对我来说无法正常工作.
由于重复的查询字符串参数名称,您无法使用标准助手生成此类URL.这很不幸,但事情就是这样.
为了生成这样的url,您可以使用以下内容:
var baseUrl = Url.Action("Index", "SomeController", null, Request.Url.Scheme);
var uriBuilder = new UriBuilder(baseUrl);
uriBuilder.Query = string.Join("&", Model.GroupsId.Select(x => "groupsid=" + x));
string url = uriBuilder.ToString();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1274 次 |
最近记录: |