加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 下载列表asp mvc

发布时间:2020-12-15 20:56:22 所属栏目:asp.Net 来源:网络整理
导读:我想为我的模型类的一些属性生成一个下拉列表.我正在开发一个mvc .net应用程序,我正在使用razor引擎进行查看.这是我的班级: public class present{ public DateTime jour { get; set; } public int entree_mat_h { get; set; } public int entree_mid_h { g
我想为我的模型类的一些属性生成一个下拉列表.我正在开发一个mvc .net应用程序,我正在使用razor引擎进行查看.这是我的班级:
public class present
{       
    public DateTime jour { get; set; }
    public int entree_mat_h { get; set; }
    public int entree_mid_h { get; set; }
    public int sortie_mat_h { get; set; }
    public int sortie_mid_h { get; set; }
    public int entree_mat_m { get; set; }
    public int entree_mid_m { get; set; }
    public int sortie_mat_m { get; set; }
    public int sortie_mid_m { get; set; }
    public string mac { get; set; }
    public string ip { get; set; }
}

例如,我想显示一个下拉列表,其中每个属性为0到60,这是一个整数.
@ html.dropdownlistfor()是否适用于这种情况?

解决方法

在您的视图中声明可能值的列表,在您的情况下从0到60
@{ var values = new SelectList(Enumerable.Range(0,60)); }

然后,您可以在DropDownListFor帮助器中使用它

@Html.DropDownListFor(m => m.entree_mat_h,values)
@Html.DropDownListFor(m => m.entree_mid_h,values)
....

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读