2014-10-08 77 views
0

我有幾個下拉模型,我需要添加引導窗體控件類。我正在努力轉換這個字符串來接受這個類。將類添加到@ html.DropDownListFor

我會很感激的幫助。

我已經把

, new { @class = "form-control"} 

無處不在的行沒有成功。

@Html.DropDownListFor(model => model.SelectedSourceAccount, new 
SelectList(Model.AllWithdrawalAccounts.Select(x => new {Value = x.Id, Text = 
x.NameAndAvailableBalance}), "Value", "Text"), Model.SelectedSourceAccount) 

回答

1

嘗試(注意創建選擇列表中,當你不需要.Select(..)

@Html.DropDownListFor(model => model.SelectedSourceAccount, new SelectList(Model.AllWithdrawalAccounts, "Id", "NameAndAvailableBalance"), new { @class = "form-control"}) 
0
@Html.DropDownListFor(model => model.SelectedSourceAccount, new 
SelectList(Model.AllWithdrawalAccounts.Select(x => new {Value = x.Id, Text = 
x.NameAndAvailableBalance}),string.Empty, new { @class = "dropdown" }) 
+0

不要給代碼唯一的答案。簡要解釋答案,以便對其他人也有幫助。 – Ravimallya 2014-10-08 05:18:08

0

由於有對dropdown多個重載方法,我想你已經使用了錯誤的重載方法。您可以使用提供的正確的重載方法。