如何使用空白和html属性填充DropDownList?

时间:2014-09-03 18:46:38

标签: asp.net-mvc razor drop-down-menu

我已按以下方式设置下拉列表。但是,我似乎无法在下拉列表中找到空白字符串。用于设置类的html属性。

控制器

 Dim items As IEnumerable(Of SelectListItem) = _
     db.Persons.[Select](Function(m) New  _
     SelectListItem() With { _
       .Value = m.ID.ToString(), _
       .Text = m.LastName & ", " & m.FirstName}).OrderBy(Function(n) n.Text)
 ViewBag.AllPlayers = items

查看

@Html.DropDownList("AllPlayers", "")

也尝试了......

@Html.DropDownList("AllPlayers", Nothing, New With { .class = "form-control" })

2 个答案:

答案 0 :(得分:0)

试试这段代码。

@Html.DropDownList("AllPlayers", New SelectList(New List(Of Object){ 
                   New { value = "" , text = ""  },
                }, "value", "text"), New With { .class = "form-control" })

我对VB.NET语法不是很熟悉,但我希望它能正常工作。

答案 1 :(得分:0)

不确定我最初是如何错过这个的。但是,这是我用过的。

@Html.DropDownList("AllPlayers", Nothing, "", New With {.class = "form-control"})
相关问题