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 17, 2017, 10:31 PM EDT
Nice post Mani Kandan bro, keep it up.
pruthvi rajPosted Jan 18, 2017, 4:54 AM EST
The link is not working what u have sent Abhilash Jayakumar thank u replying
Abhilash J APosted Jan 18, 2017, 3:35 AM EST
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, 3:12 AM EST
pruthvi raj : It is easy. First select list of checked checkbox values.
pruthvi rajPosted Jan 18, 2017, 2:10 AM EST
As soon as possible guys i need to insert values in database
pruthvi rajPosted Jan 18, 2017, 2:10 AM EST
Help me to save multiselect dropdown plugin to database
Ajeet MishraPosted Sep 14, 2015, 4:50 AM EDT
nice
Abhilash J APosted Sep 8, 2015, 12:47 AM EDT
Thank You, Sir!!
Santhakumar MunuswamyPosted Sep 5, 2015, 12:23 AM EDT
Nice share