jquery - How to retrieve selected values from multiselect list -


<h2>my chart</h2> @using (html.beginform()) {     <div>         @html.listbox("chosen")     </div>     <br/>     <input type="submit" value="submit"/> }  <script type="text/javascript">      $(document).ready(function() {          $("#chosen").select2(         {             placeholder: "choose states ",             width:300         });     }); </script> 

this script making multiselect dropdown, works. want collect these values , store them in array or list can use in controller have no idea how that.

this controller method populating list

public actionresult charter() {     viewbag.chosen = new multiselectlist(_mydb.states,"id","name");      return view(); } 

this model

public class state {     public int id { get; set; }      [required]     [stringlength(50)]     public string name { get; set; }      public int stations { get; set; } } 

[httppost] public actionresult charter(state[] states) {     //here type logic      return view(); } 

or try one:

[httppost] public actionresult charter(int[] ids) // can try this: **ilist<int> ids** {     //here type logic      return view(); } 

Comments