Solved

How to make DropDownListFor into a jQuery multiselect

Posted on 2016-08-17
6
48 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 to hide html tags in text area 4 32
Why does my button disappear? 3 28
Having problem getting this to work 2 18
jQuery Validate 4 16
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now