MVC5 下拉框(多選)

來源:互聯網
上載者:User

標籤: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 下拉框(多選)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.