如何在cshtml中使用下拉列表?
我正在使用下面的代码,现在看起来像一般的HTML,但问题是没有应用引导样式。
<div class="col-md-10">
@{
List<SelectListItem> listItems = new List<SelectListItem>();
listItems.Add(new SelectListItem
{
Text = "AtlantaPort",
Value = "AtlantaPort"
});
listItems.Add(new SelectListItem
{
Text = "NewJersyTerminal",
Value = "NewJersyTerminal",
Selected = true
});
listItems.Add(new SelectListItem
{
Text = "AWS",
Value = "AWS"
});
}
@Html.DropDownListFor(model => model.PortORterminal, listItems, "AtlantaPort", new { htmlAttributes = new { @class = "form-control", } }) )
</div>
提前致谢
最佳答案
用 :
@Html.DropDownList("yourDropName", listItems, new { @class = "form-control" })
您的代码已编辑:
@{
List<SelectListItem> listItems = new List<SelectListItem>();
listItems.Add(new SelectListItem
{
Text = "AtlantaPort",
Value = "AtlantaPort"
});
listItems.Add(new SelectListItem
{
Text = "NewJersyTerminal",
Value = "NewJersyTerminal",
Selected = true
});
listItems.Add(new SelectListItem
{
Text = "AWS",
Value = "AWS"
});
}
@Html.DropDownList("yourDropName", listItems, new { @class = "form-control" })
</div>