Model 如何将数据从模型类转换为列表

Model 如何将数据从模型类转换为列表,model,asp.net-identity,selectlist,Model,Asp.net Identity,Selectlist,有人知道如何将数据从Identity Framework模型类转换为selectlist吗 我想导出特定模型类中的所有数据,并将其复制到selectlist中 有人能告诉我怎么做吗 我已经试过了: 我尝试了这段代码,但它只从枚举中读取预填充的数据。Ans我想用modelclass中的数据填充selectbox public class Student { public int StudentId { get; set; } [Display(Name="Name")] p

有人知道如何将数据从Identity Framework模型类转换为selectlist吗

我想导出特定模型类中的所有数据,并将其复制到selectlist中

有人能告诉我怎么做吗

我已经试过了:

我尝试了这段代码,但它只从枚举中读取预填充的数据。Ans我想用modelclass中的数据填充selectbox

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" })
上述内容不符合我的需要,因为它们使用的是枚举中定义的数据,而不是模型类本身的数据


Gr.

一个代码示例将有助于更好地理解您的案例。@dmigo我刚刚用一个示例更新了我的问题