如何在 mvc razor View 的一个 View 中的特定时间获取和插入数据?我的意思是在创建 View 中从数据库中填写一个下拉列表。
我要在添加主题和骗子模型时填写以下内容。
- 部门列表
- 学期列表
- 标准 list
- 流列表
作弊模型:
namespace firstapp.Models
{
public class chepter
{
[ForeignKey("dip_id")]
public int dipart_id { get; set; }
public int chep_id { get; set; }
public string subject { get; set; }
public string chepter { get; set; }
public List<dipartment> dipartlist { get; set; }
public List<dipartment> stdlist { get; set; }
public List<dipartment> semlist { get; set; }
public List<dipartment> stremlist { get; set; }
}
}
部门模型:
namespace firstapp.Models
{
public class dipartment
{
public int dip_id { get; set; }
public string dipart { get; set; }
public string std { get; set; }
public string sem { get; set; }
public string strem { get; set; }
}
}
最佳答案
@Html.DropDownListFor(model => model.dipart_id, new SelectList(Model.dipartlist.Select(s => new SelectListItem() { Value = s.dip_id, Selected = false, Text = s.dipart })), "Select")
关于c# - 在创建 View 中从数据库中填充下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24285901/