如何在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>
先谢谢
答案 0 :(得分:2)
使用:
@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>
答案 1 :(得分:1)
尝试用此替换你的最后一行:
HTTP_HOST