将多个数据角色放入razor DropDownList

时间:2014-10-15 23:11:45

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

有没有办法将多个数据角色放入剃刀代码?我需要它来为jquery标记器标记我的选择列表。

我需要做以下事情:

@Html.DropDownList("Orientations", (SelectList)ViewBag.Orientations, "None", new { @multiple data-role="tagsinput", @class = "form-control" })

来自:

@Html.DropDownList("Orientations", (SelectList)ViewBag.Orientations, "None", new { @class = "form-control" })

但是这样做不起作用。
谢谢!

1 个答案:

答案 0 :(得分:2)

您需要将data-role中的连字符更改为下划线(html将使用连字符进行渲染)。

@Html.DropDownList("Orientations", (SelectList)ViewBag.Orientations, "None", new { multiple="multiple", data_role="tagsinput", @class = "form-control" })

或者你可以使用

@Html.ListBox("Orientations", (SelectList)ViewBag.Orientations, "None", new { data_role="tagsinput", @class = "form-control" })

@Html.ListBox为您呈现属性multiple="multiple"