Akila

Akila

  • NA
  • 216
  • 30.7k

Multiselected view in dropdownlist using MVC

Apr 23 2021 12:42 PM
I am adding the checkbox in Dropdownlist for multiview..My code is below.
 
In view page:
  1. <div class="col-md-10">  
  2. @Html.ListBoxFor(model => model.SkillArray, (IEnumerable<SelectListItem>)ViewBag.SkillList as SelectList,  
  3. new { style = "width:100%", @id = "Skill", multiple = "multiple", @class = "form-control", })  
  4. @Html.ValidationMessageFor(model => model.Skill, ""new { @class = "text-danger" })  
  5. </div>  
In javascript:
  1. <script type="text/javascript">  
  2. $(function () {  
  3. jQuery('#Rolelist').multiselect({  
  4. includeSelectAllOption: true  
  5. });  
  6. });  
  7. </script>  
In HomeController:(for creating dropdownlist)
  1. string constr = ConfigurationManager.ConnectionStrings["Databaseconnection"].ToString();    
  2. SqlConnection cons = new SqlConnection(constr);    
  3. SqlDataAdapter _daa = new SqlDataAdapter("Select * From Skill", constr);    
  4. DataTable _dt1 = new DataTable();    
  5. _daa.Fill(_dt1);    
  6. ViewBag.SkillList = ToSelectList(_dt1, "id""Skill");    
  7. return View();   
Then am using this Bootstrap links:
  1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>  
  2. <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>  
  3. <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>  
  4. <!---->  
  5. <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/css/bootstrap-multiselect.css" rel="stylesheet" />  
  6. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  
  7. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  
  8. <!---dropdown checkbox-->  
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>  
  10. <!---->  
(Am using this above links for my project total design is affected..also the checkbox is not responding)
 
How to resolve this).

Answers (3)