Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Initially the dropdown values are loaded from the model, now it needs to be loaded static values. so I'm using the below type to load the dropdown, for this I can't able to add the CSS-class. Need advice
HTML
@Html.DropDownList("RoundOffInterval", new List<SelectListItem>
    {
    new SelectListItem{ Text="Select Roundoff Interval",Value=""},
    new SelectListItem{ Text="5",Value = "5" },
    new SelectListItem{ Text="10", Value = "10" },
    new SelectListItem{ Text="15", Value = "15" },
    new SelectListItem{ Text="20", Value = "20" },
    new SelectListItem{ Text="30", Value = "30" },})


Before i used the below type :
HTML
@Html.DropDownListFor(m => m.RoundoffInterval, new SelectList(Model.RoundoffIntervalList, "Id", "Name"), "Select Roundoff Interval ", new { id = "RoundoffInterval", name = "RoundoffInterval", @class = "select2_demo_4 form-control" })
Posted
v2

Try with this format

C#
@Html.DropDownList("RoundOffInterval", new List<SelectListItem>
{
  new SelectListItem{ Text="Select Roundoff Interval",Value=""},
  new SelectListItem{ Text="5",Value = "5" },
  new SelectListItem{ Text="10", Value = "10" },
  new SelectListItem{ Text="15", Value = "15" },
  new SelectListItem{ Text="20", Value = "20" },
  new SelectListItem{ Text="30", Value = "30" }
}, htmlAttributes)

With htmlAttributes in your case is new {@class="select2_demo_4 form-control"}

Hope it help!
 
Share this answer
 
v2
@Html.DropDownList("RoundOffInterval", new List<SelectListItem>
             {
             new SelectListItem{ Text="Select Roundoff Interval",Value=""},
             new SelectListItem{ Text="5",Value = "5" },
             new SelectListItem{ Text="10", Value = "10" },
             new SelectListItem{ Text="15", Value = "15" },
             new SelectListItem{ Text="20", Value = "20" },
             new SelectListItem{ Text="30", Value = "30" },"value","text",2}, new {@class="yourClassName"})
 
Share this answer
 
ViewBag.company= new SelectList(db.company, "comname", "comname");

@Html.DropDownList("company", (IEnumerable<selectlistitem>)ViewBag.company, "-Select company-", new { @class = "form-control" })
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900