2014-10-08 43 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多个重载方法,我想你已经使用了错误的重载方法。您可以使用提供的正确的重载方法。