2014-09-03 46 views
0

我已經按照以下方式設置了我的下拉列表。但是,我似乎無法在下拉列表中獲得一個空字符串,以便設置一個類。如何使用空白和html屬性填充DropDownList?

控制器

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" }) 

回答

0

試試這個代碼。

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

我不是很熟悉VB.NET語法,但我希望它能工作。

+0

似乎無法得到這個工作。 – daveomcd 2014-09-03 19:43:27

0

不知道我最初錯過了這個。不過,這是我用過的那個。

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