3

在我的 MVC3 项目中,我有一个控制器“测试”,使用这种方法进行索引操作

Function Index(fields() As String) As ViewResult
...

然后在视图上我有一个多选下拉列表

@Html.ListBox("fields", New MultiSelectList(my_list, "Value", "Text")) 

一切正常,但是当我尝试创建一个 Actionlink 时,像这样在查询字符串中传递参数“字段”的多个值

@Html.ActionLink("TestLink", "Index", New With {
         .fields = "value1&fields=value2"}) 

我在带有查询字符串编码的 HTML 源代码中得到以下断开的链接

<a href="/Test/Index?fields=value1%26fields%3Dvalue2">TestLink</a> 

如何通过 ActionLink 将多个值传递给查询字符串参数?

4

1 回答 1

0

If you want to do this dynamically by fetching the values from the listbox simply put the listbox inside a form whose action is pointing the controller action you want to invoke and then use a submit button. HTML will then do the job for you.

If you want to generate an ActionLink you could use the following:

@Html.ActionLink(
    "TestLink", 
    "Index", 
    New RouteValueDictionary() From { 
        { "fields[0]", "value1" }, 
        { "fields[1]", "value2" } 
    }
)
于 2013-01-21T15:12:44.620 回答