Solved

How to make DropDownListFor into a jQuery multiselect

Posted on 2016-08-17
6
38 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 7

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 7

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 7

Expert Comment

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now