Assign Attribute to @Html.DropdownList

前端 未结 2 1709
时光说笑
时光说笑 2021-01-03 00:10

I want to assign some ID attribute name to my Dropdown list which is using data from the ViewBag as,

ViewBag.Group = new SelectList(group, \"GroupId\", \"Nam         


        
相关标签:
2条回答
  • 2021-01-03 00:45

    You should be using something like this

    @Html.DropDownList("Group",null,new{@id="testID"});
    

    because the data for the DropDownList comes from the ViewBag to name Group

    0 讨论(0)
  • 2021-01-03 00:46

    Try it:

    In controller

      ViewBag.EmployeeId = new SelectList(db.tb_employees, "id", "last_name");
    

    In View

    @Html.DropDownList("EmployeeId", (IEnumerable<SelectListItem>)ViewBag.EmployeeId,"Show All", new { @class = "form-control" })
    
    0 讨论(0)
提交回复
热议问题