Solved

How to make DropDownListFor into a jQuery multiselect

Posted on 2016-08-17
6
70 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Html using "Or" in condition 3 27
Hta File displays dynamic File names 4 50
REST call Failing 1 15
Diff of the day 2 9
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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 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)

726 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