有谁知道将数据从身份框架模型类转换为选择列表的方法。
我想从该特定模型类中导出所有数据,并将其复制到选择列表中。
有人可以解释一下我该怎么做吗?
我已经尝试过:https ://www.tutorialsteacher.com/mvc/htmlhelper-dropdownlist-dropdownlistfor
我试过这段代码,但它只从枚举中读取预填充的数据。Ans 我想用模型类中的数据填充选择框。
public class Student
{
public int StudentId { get; set; }
[Display(Name="Name")]
public string StudentName { get; set; }
public Gender StudentGender { get; set; }
}
public enum Gender
{
Male,
Female
}
@using MyMVCApp.Models
@model Student
@Html.DropDownList("StudentGender",
new SelectList(Enum.GetValues(typeof(Gender))),
"Select Gender",
new { @class = "form-control" })
以上不符合我的需要,因为它们使用的是枚举中定义的数据,而不是模型类本身的数据。
格。