ASP.NET MVC View User Control - how to set IDs?

前端 未结 3 504
南旧
南旧 2021-02-04 17:38

I need a dropdown list on my page that will allow a user to select their state. Since this is probably a control that will be used elsewhere, I thought it would be a good idea

3条回答
  •  青春惊慌失措
    2021-02-04 18:03

    Take a look at the Html.DropDownList helper method. It has a number of overloads that allow you to pass the list data and set the selected item. the simplest version just sets the name of the select.

    <%= Html.DropDownList("SelectStates"); %>
    

    If there is a value in the ViewData["SelectStates"] that is of type MultiSelectList then the list will be automatically populated.

提交回复
热议问题