Add Class Dropdownlistfor

Asked

Viewed 37 times

0

How do I enter @class = "form-control" in the code below?

    <div class="form-group">
        <label for="disabledSelect" class="control-label col-md-2">Status:</label>
        <div class="col-md-10">
            @Html.DropDownListFor(s => s.Status, new List<SelectListItem>
            {
                new SelectListItem { Value = "Ativo", Text = "Ativo" },
                new SelectListItem { Value = "Inativo", Text = "Inativo" },
            }, @Model.Status, @Model.Status)
        </div>
    </div>
  • Because the @Model.Status repeat twice at the end?

1 answer

1

In my case I use it as follows.

@Html.DropDownListFor(model => model.Department, (IEnumerable<SelectListItem>)ViewBag.Depts, "", htmlAttributes: new { @id = "departmentList", @class = "form-control" })

In your case it stays that way

@Html.DropDownListFor(s => s.Status, new List<SelectListItem>
{
    new SelectListItem { Value = "Ativo", Text = "Ativo" },
    new SelectListItem { Value = "Inativo", Text = "Inativo" },
}, @Model.Status, htmlAttributes: new { @id = "isActive", @class = "form-control" })

Browser other questions tagged

You are not signed in. Login or sign up in order to post.