Dropdown in MVC

后端 未结 6 712
甜味超标
甜味超标 2020-12-06 15:22

In my MVC application, I need to add a dropdown that would show a list of domain names.

I already have a ViewModel that contains multiple properties. I am not sure w

6条回答
  •  猫巷女王i
    2020-12-06 15:43

    Once you have the list on your controller pass it to the view (as model or using ViewBag) and then use the helper:

    Html.DropDownList(
        string name,
        IEnumerable selectList,
        string optionLabel,
        object htmlAttributes) 
    

    Or (MVC 3)

    @Html.DropDownListFor(model => model.Property.ID,
        new SelectList(model.PropertyList, "ID", "Type"))
    

提交回复
热议问题