MVC5 drop-down box (Multiple choices) and mvc5 drop-down box (Multiple choices)

Source: Internet
Author: User

MVC5 drop-down box (Multiple choices) and mvc5 drop-down box (Multiple choices)

1. Model

[Display (Name = "")] [Required] public int [] job {get; set;} // job attribute public IEnumerable <Item> joblist {get; set ;} // multi-choice box attributes

2. cotroller

[Description ("job binding")] [LoginAllowView] private List <Item> bindPosts () {StringBuilder sb = new StringBuilder (); sb. append ("SELECT r01, r02,"); sb. append ("FROM rac_file"); // query the position id and name 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 aaai000000info () {var m = new jobModel (); m. joblist = bindPosts (); // bind the position 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>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.