码迷,mamicode.com
首页 > Web开发 > 详细

MVC5 下拉框(多选)

时间:2017-06-27 15:04:02      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:job   tor   actor   new   UI   label   查询   下拉框   ble   

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>

 

MVC5 下拉框(多选)

标签:job   tor   actor   new   UI   label   查询   下拉框   ble   

原文地址:http://www.cnblogs.com/Sakura007/p/7084780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!