gpt4 book ai didi

c# - 在创建 View 中从数据库中填充下拉列表

转载 作者:太空宇宙 更新时间:2023-11-03 15:54:19 25 4
gpt4 key购买 nike

如何在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com