Search code examples
asp.net-mvcasp.net-mvc-4razor-2

Adding a custom class to DropDownList in MVC 4


Well here I'm trying to add a Bootstrap class to the DropDownList generated by Razor, but it keeps giving me squigglies.

 @Html.DropDownList("NationalityId", String.Empty, new {@class="form-control"})

Any recommendation as to how I can get this to work.


Solution

  • it works:

    @Html.DropDownList("NationalityId",new List<SelectListItem>(), new {@class="form-control"})
    

    Result html:

    <select name="NationalityId" id="NationalityId" class="form-control"></select>