Step 1: MVC set Viewdata in controller inside save get method using foreach loop.
Step 2: Inside View write foreach loop for multiselect dropdown with checkboxlist. Here's the code snippet:
- <div id="divStudentlist" style="height: 100px; overflow: auto; border: solid; width: 150px;">
- @foreach (var items in ViewData["Items"] as List
- <SelectListItem>) {
- <table width="100%">
- <tr>
- <td width="20px">
- <input type="checkbox" value="@items.Value" class="chkclass" />
- </td>
- <td width="100px">
- @items.Text
- </td>
- </tr>
- </table>
- }
- </div>
Before that, you should place @Html.Hidden("idlist") inside Ajax.BeginForm and now write jQuery,
- var idslist = "";
- $("input:checkbox[class=chkclass]").each(function() {
- if ($(this).is(":checked")) {
- var userid = $(this).attr("value");
- idslist = idslist + userid + ',';
- }
- });
- $("#idlist").val(idslist);
- string[] i1;
- string items = frm["idlist"];
- if (items != null) {
- i1 = items.Split(new [] {
- ","
- }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < i1.Length; i++) {
- string s = i1[i]; /*Inside string type s variable should contain items values */
- }
- }

Nazmul BadshaPosted Oct 18, 2017, 2:31 AM
Nice post Mani Kandan bro, keep it up.
pruthvi rajPosted Jan 18, 2017, 9:54 AM
The link is not working what u have sent Abhilash Jayakumar thank u replying
Abhilash J APosted Jan 18, 2017, 8:35 AM
pruthvi raj : please look up it: http://www.c-sharpcorner.com/blogs/multiselect-dropdown-with-checkbox-insert-values-to-database-mvc4
Abhilash J APosted Jan 18, 2017, 8:12 AM
pruthvi raj : It is easy. First select list of checked checkbox values.
pruthvi rajPosted Jan 18, 2017, 7:10 AM
As soon as possible guys i need to insert values in database
pruthvi rajPosted Jan 18, 2017, 7:10 AM
Help me to save multiselect dropdown plugin to database
Ajeet MishraPosted Sep 14, 2015, 8:50 AM
nice
Abhilash J APosted Sep 8, 2015, 4:47 AM
Thank You, Sir!!
Santhakumar MunuswamyPosted Sep 5, 2015, 4:23 AM
Nice share