MVC5 下拉框(多选)

2018-06-22 06:13:00来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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>

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:路由和数据传递

下一篇:MVC+EasyUI+三层新闻网站建立(八,详情页面完成)