我一直在试图弄清楚如何正确使用语法,以便在MVC中加载带有简单字符串列表的下拉列表。
什么是正确的格式?
以下代码
@Html.DropDownList("VMO", List<string>(ViewBag.VMOList), new { @class = "form-control SearchCriteria", id = "VMO", name = "VMO", multiple = "multiple"})
给我错误
"Non-invocable member 'List<T> cannot be used like a method.
答案 0 :(得分:1)
如果要使用Select List
和list of string
来制作@Html.DropDownList()
,则应如下所示:
@Html.DropDownList("VMO", new SelectlIst(ViewBag.VMOList),"Select Item", new { @class = "form-control SearchCriteria", id = "VMO", name = "VMO", multiple = "multiple"})
或者如果您想使用Select List
和list of object
来制作@Html.DropDownList()
,则应该如下:
@Html.DropDownList("VMO", new SelectlIst(ViewBag.VMOList,"ObjectId","ObjectName"),"Select Item", new { @class = "form-control SearchCriteria", id = "VMO", name = "VMO", multiple = "multiple"})