最初,下拉值是从模型中加载的,现在需要加载“静态值”。所以我使用下面的类型为此加载下拉列表,我无法添加 CSS 类。需要建议
@Html.DropDownList("RoundOffInterval", new List<SelectListItem>
{
new SelectListItem{ Text="Select Roundoff Interval",Value=""},
new SelectListItem{ Text="5",Value = "5" },
new SelectListItem{ Text="10", Value = "10" },
new SelectListItem{ Text="15", Value = "15" },
new SelectListItem{ Text="20", Value = "20" },
new SelectListItem{ Text="30", Value = "30" }
})
在我使用以下类型之前:
@Html.DropDownListFor(m => m.RoundoffInterval, new SelectList(Model.RoundoffIntervalList, "Id", "Name"), "Select Roundoff Interval ", new { id = "RoundoffInterval", name = "RoundoffInterval", @class = "select2_demo_4 form-control" })
最佳答案
试试这个:
@Html.DropDownList(
"RoundOffInterval",
new List<SelectListItem>
{
new SelectListItem{ Text="Select Roundoff Interval",Value=""},
new SelectListItem{ Text="5",Value = "5" },
new SelectListItem{ Text="10", Value = "10" },
new SelectListItem{ Text="15", Value = "15" },
new SelectListItem{ Text="20", Value = "20" },
new SelectListItem{ Text="30", Value = "30" },
},
new {@class="select2_demo_4 form-control"})
关于c# - 如何将类添加到@Html.DropDownList?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34505726/