Binding Data To DropDownList MVC Razor

前端 未结 1 1780
北海茫月
北海茫月 2021-01-23 08:26

I have just started with my project using MVC and Razor. Now I am encountering a problem when it comes to binding data coming from the database to a dropdownlist. Please refer o

1条回答
  •  抹茶落季
    2021-01-23 09:17

    yopu can't put a foreach in a constructor, try:

    var items = new List();
    foreach(var x in SpecializationList)
    {
               items.add(new SelectListItem { Value = x.SpecializationID.ToString(), Text = x.SpecializationDescription });
    }
    
    obj.Items = items;
    

    Edited

    0 讨论(0)
提交回复
热议问题