Solved

How to make DropDownListFor into a jQuery multiselect

Posted on 2016-08-17
6
59 Views
Last Modified: 2016-08-17
Hello, I have the following dropdown which populates fine. I want to make it a multiselect using jQuery.  jQuery is being referenced on the view.

This is my dropdown:
@Html.DropDownListFor(m => m.StandardIndustries, Model.StandardIndustries, "Id", "Name")


This is how it is being rendered:

<select id="StandardIndustries" name="StandardIndustries">
<option value="1">Advertising</option>
<option value="2">Agriculture</option>
<option value="3">Banking / Finance / Investments</option>
<option value="4">Chemicals</option>
</select>
0
Comment
Question by:Scott Baldridge
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:James Bilous
ID: 41759778
This is a C# question, not Jquery or Javascript. You need to use ListBoxFor instead of DropDownListFor
0
 

Assisted Solution

by:Scott Baldridge
Scott Baldridge earned 0 total points
ID: 41759819
Thank you for responding. I'm still learning. I need a dropdown with check boxes to allow the user to select multiple items. I thought that adding a class of multiselect when jQuery is referenced will do the trick. Are you saying I need to create a ListBoxFor then make it a dropdown with CSS or something?
0
 
LVL 8

Accepted Solution

by:
James Bilous earned 500 total points
ID: 41759914
Do you have to have checkboxes? The multi select accomplishes what you are trying to do without them.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:Scott Baldridge
ID: 41759965
Yes, but I figured out my issue. The solution is similar to this bootstrap example: http://jsfiddle.net/ejqngpn5/

Except we don't use bootstrap and have similar resources.

When I found the article posted above, I made sure all the references were included to do multiselect and then it worked as expected.
0
 

Author Closing Comment

by:Scott Baldridge
ID: 41759976
Thank you for your assistance. I appreciate that you responded to my call for help. Your questions made me re-evaluate what I was trying to achieve. I was able to then find a similar solution, work through an example and notice what was missing in my environment.
0
 
LVL 8

Expert Comment

by:James Bilous
ID: 41760006
No problem, glad you figured it out!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I repopulate form fields that error after server side validation without using javascript? 1 29
jqury 17 30
Select case on click 3 16
Button and js nou working 3 8
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question