MVC5 下拉框(多选)_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > MVC5 下拉框(多选)

MVC5 下拉框(多选)

 2017/6/28 5:58:54  百变小樱007  程序员俱乐部  我要评论(0)
  • 摘要:1.Model[Display(Name="职位")][Required]publicint[]job{get;set;}//职位属性publicIEnumerable<Item>joblist{get;set;}//多选框属性2.cotroller[Description("职位绑定")][LoginAllowView]privateList<Item>bindPosts(){StringBuildersb=newStringBuilder()
  • 标签:MVC

1.Model

[Display(Name = "职位")]
 [Required]
 public int[] job { get; set; }   //职位属性

 public IEnumerable<Item> joblist { get; set; }  //多选框属性

2.cotroller

[Description("职位绑定")]
[LoginAllowView]
 private List<Item> bindPosts()
 {
            StringBuilder sb = new StringBuilder();
            sb = new StringBuilder();
            sb.Append(" SELECT r01,r02, ");
            sb.Append(" FROM rac_file ");  //查询职位id和名称
            DataTable dt = sqlHelper.getData(sb.ToString());
            var factorOptions = dt.AsEnumerable().Select(row => new Item
            {
                Name =  Utils.ObjToStr(row["r01"]),
                Id = Utils.ObjToInt(row["r02"], 0)
            }).ToList();
            return factorOptions; 
}
public ActionResult aaai001_info()
 {
     var m=new jobModel();
     m.joblist=bindPosts();   //绑定职位
     retutn view(m);
}

3.View

<div class="form-group">
       @Html.LabelFor(m => m.Positions, new { @class = "col-sm-2 control-label" })
       <div class="col-sm-10">
           @Html.ListBoxFor(model => model.job,new MultiSelectList(Model.joblist,"Id", "Name"), new { @class = "form-control select2", multiple = "multiple",           style = "width: 100%;" })
           <span id="states-loading-progress" style="display: none;">Please wait..</span>
           @Html.ValidationMessageFor(m => m.job, "", new { @class = "text-danger" })
       </div>
 </div>

 

上一篇: C# 视频转换类 下一篇: C# FTP操作类
发表评论
用户名: 匿名