How to use Dropdown list in cshtml

asp.net-mvc entity-framework razor-2

Question

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

1
3
3/7/2015 5:15:26 AM

Popular Answer

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>
3
3/10/2015 8:01:30 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow