Can't get my DropDownListFor to select a selected SelectListItem item in a Dropdown menu

前端 未结 1 341
南旧
南旧 2021-01-21 01:35

I have a collection of items populated to a drop down menu:

string myUserName = \"PopulatedWithSomeUser\";

var users= from x in userRepository.GetAll()
    sele         


        
相关标签:
1条回答
  • 2021-01-21 02:14

    As a first parameter you should pass a field for what you are going to receive data after form submit. Everything else looks right:

    @Html.DropDownListFor(model=>model.UserId, Model.Users)
    

    Or if you are going to provide your own id and name - it would be better to use this (msdn):

    @Html.DropDownList("add-user-list", Model.Users, new {id = "add-user-list"})
    
    0 讨论(0)
提交回复
热议问题