How to use dropdown list in cshtml? I am using below code ,Now it looks like general HTML but problem is not apply the bootstrap styles.
<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>
Thanks in Advance
Use :
@Html.DropDownList("yourDropName", listItems, new { @class = "form-control" })
Your code edited:
@{
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>