I tried to used bootstrap4 dropdownlist with check box to allowed user pic email from ListBoxFor when he/she click on the ListBoxFor. I found many articles show only when click on the button and then show the dropdown menu with check box, what I have is
ListBoxFor and I want every time when user click on the text area on listboxfor it will show dropdowm menu for list of users email. like:
DashboardCode Multiselect JQuery Plugin for Bootstrap 4.
my approach :
my controller
public ActionResult Index(EmailViewModel model)
{
ModelState.Clear();
var ProctorList = (from U in db2.A2
join P in db2.A2on U.UserId equals P.Proctor_User_Id
where U.Email != null
select new AdminRoleViewModel
{
ProctorEmail = A1.Email,
ProctorUserId = A2.Proctor_User_Id.ToString(),
ProctorId = A2.ProctorId
}).ToList();
ViewBag.ProcEmail = ProctorList;
model.EmailList = new MultiSelectList(ProctorList, "ProctorId", "ProctorEmail");
return View(model);
}
The code you shared has a few potential issue but it is incomplete and I'm not sure what the actual issue is.
Anyway, below is a working and tested example. Note: my site uses HTTPS so I have to change the JS and CSS file references to use HTTPS. Be sure you use standard debugging tools like the browser's dev tools.
public class EmailViewModel
{
public List<int> ProctorIds { get; set; }
public MultiSelectList EmailList { get; set; }
}
public class Proctor
{
public int ProctorId { get; set; }
public string ProctorEmail { get; set; }
}
public class BootstrapController : Controller
{
private readonly IEnumerable<Proctor> list;
public BootstrapController()
{
list = new List<Proctor>()
{
new Proctor() {ProctorId=1, ProctorEmail="ProctorEmail1@mail.com"},
new Proctor() {ProctorId=2, ProctorEmail="ProctorEmail2@mail.com"},
new Proctor() {ProctorId=3, ProctorEmail="ProctorEmail3@mail.com"}
};
}
[HttpGet]
public IActionResult Index()
{
EmailViewModel vm = new EmailViewModel()
{
EmailList = new MultiSelectList(list, "ProctorId", "ProctorEmail")
};
return View(vm);
}
[HttpPost]
public IActionResult Index(List<int> ProctorIds)
{
return Json(new { ProctorIds = ProctorIds });
}
}
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
I used your code and it show only dropdown without check box for each email. I used browser dev tool and it said Failed to load resource: the server responded with a status of 404 (Not Found) BsMultiSelect.js
I tested my code and it shows checkboxes perfectly. Again, you are doing something wrong. Share code that reproduces this issue if you want community debugging support.
I recommend performing basic troubleshooting to find where you made a mistake. Open the browsers dev tools (F12) and look for error in the console and network tab. This only takes a few seconds to look for errors.
The following example does not use a layout page and file references are to CDNs. This will fix the issues with your CSS and JS library refences. I'll assume the model being passed is correct.
Member
35 Points
163 Posts
Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in ASP.Ne...
Mar 03, 2021 08:22 PM|luay20032003|LINK
I tried to used bootstrap4 dropdownlist with check box to allowed user pic email from ListBoxFor when he/she click on the ListBoxFor. I found many articles show only when click on the button and then show the dropdown menu with check box, what I have is ListBoxFor and I want every time when user click on the text area on listboxfor it will show dropdowm menu for list of users email. like: DashboardCode Multiselect JQuery Plugin for Bootstrap 4.
my approach :
my controller
my view
All-Star
53641 Points
24010 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 03, 2021 10:01 PM|mgebhard|LINK
The code you shared has a few potential issue but it is incomplete and I'm not sure what the actual issue is.
Anyway, below is a working and tested example. Note: my site uses HTTPS so I have to change the JS and CSS file references to use HTTPS. Be sure you use standard debugging tools like the browser's dev tools.
Participant
1110 Points
371 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 03:03 AM|Jerry Cai|LINK
Hi, luay20032003
Do you want the form like this? You can check this brief demo:
Result:
Here is the tutorial link, more details in it:
https://www.jqueryscript.net/form/Bootstrap-4-Multi-Select-BsMultiSelect.html
Best Regards,
Jerry Cai
Member
35 Points
163 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 03:01 PM|luay20032003|LINK
I used your code and it show only dropdown without check box for each email. I used browser dev tool and it said Failed to load resource: the server responded with a status of 404 (Not Found) BsMultiSelect.js
All-Star
53641 Points
24010 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 03:03 PM|mgebhard|LINK
Then you did something wrong. Share your code if you want the community to find the bug(s).
Member
35 Points
163 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 03:17 PM|luay20032003|LINK
I used your code and I can't see the checkbox ?
All-Star
53641 Points
24010 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 03:30 PM|mgebhard|LINK
I tested my code and it shows checkboxes perfectly. Again, you are doing something wrong. Share code that reproduces this issue if you want community debugging support.
I recommend performing basic troubleshooting to find where you made a mistake. Open the browsers dev tools (F12) and look for error in the console and network tab. This only takes a few seconds to look for errors.
Member
35 Points
163 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 03:51 PM|luay20032003|LINK
this is my controller
this is the view
I check debug tool and I got no error
All-Star
53641 Points
24010 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 04:05 PM|mgebhard|LINK
Did you add a reference to the bootstrap-multiselect.css file in the _AdminMasterLayout.cshtml layout page?
<head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>@ViewData["Title"] - MvcDemo</title> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> <link href="https://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="~/css/site.css" /> </head>
Member
35 Points
163 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 04:21 PM|luay20032003|LINK
I just added it and same thing
Member
35 Points
163 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 04:22 PM|luay20032003|LINK
Browser debug too say Email:53 Uncaught TypeError: $(...).bsMultiSelect is not a function
All-Star
53641 Points
24010 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 04:23 PM|mgebhard|LINK
CSS file must be within the <head> section of the layout page not the View. Please read my last post!
All-Star
53641 Points
24010 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 04:25 PM|mgebhard|LINK
Seriously??? You said there were no errors. You did not check?
The error indicates you are missing jQuery references and maybe even bootstrap in your custom layout file as well.
My Layout file...
Member
35 Points
163 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 04:43 PM|luay20032003|LINK
I changed to the <head> section layout and it's same
in the browser debug tool I got : Email:47 Uncaught TypeError: $(...).bsMultiSelect is not a function
All-Star
53641 Points
24010 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 06:47 PM|mgebhard|LINK
You are not following the recommendations. Use the layout page that comes with the MVC template. Your custom layout has a lot of errors.
All-Star
53641 Points
24010 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 07:04 PM|mgebhard|LINK
The following example does not use a layout page and file references are to CDNs. This will fix the issues with your CSS and JS library refences. I'll assume the model being passed is correct.
I think you'll be interested in learning CSS and JS file references. Also, you should use standards patterns and practices found in any MVC tutorial.
Member
35 Points
163 Posts
Re: Multiple Select (Multi-Select) DropDownList with CheckBoxes from database using jQuery in AS...
Mar 04, 2021 07:24 PM|luay20032003|LINK
Thank you so much, your last code work perfect to me, I will learn more about CSS and JS references. your smart developer indeed.