I am using Bootstrap-multiselect plugin to add the multiselect dropdown value with checkboxes. Its working fine and I am getting selected value also. Following is my razor code.
@Html.ListBoxFor(model => model.Ex, new SelectList(ViewBag.ExList, "Value", "Text"), new { @class = "form-control", id = "excursion" })
Here is my Model
public class MyModel
{
public List<string> Ex { get; set; }
}
// In here I am getting my selected values from database table.
// This value is retrieve as comma separated string - item1,item2,item3
var myselected_List = obj.GetSelectedList();
// In here I am getting my all dropdown values from database table.
var myall_List = obj.GetAllList();
viewBag.ExList = myall_list.Select(x => new SelectListItem()
{
Text = x,
Value = x,
});
// I want to combine my selected list with alllist and checked the values based on my selected list
I am saving the user selected drop down values in database using comma separated data. such as text1, text2, text3.
In here my ViewBag.ExList contains list with values such as text1, text2,text3,text4, text5.
When same user load the page second time, I want to checked the text1,text2,text3 values as his earlier preferred value in dropdown.
The problem here is, I can get the data from database. I have the full data list too. But I don't know how to achieve this checked checkboxes for user selected items. Can anybody please help me.
Thanks