Assign Attribute to @Html.DropdownList

前端 未结 2 1728
时光说笑
时光说笑 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:46

    Try it:

    In controller

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

    In View

    @Html.DropDownList("EmployeeId", (IEnumerable)ViewBag.EmployeeId,"Show All", new { @class = "form-control" })
    

提交回复
热议问题