Use jQuery Select2 with ASP.NET MVC
NickName:Bryan Ask DateTime:2016-04-01T23:46:06

Use jQuery Select2 with ASP.NET MVC

I'm trying to use Select2 in Razor in ASP.NET MVC. But I can't get work.

  $(document).ready(function () {
            $(".genreOptions").select2({
                tags: true,
                ajax: {
                    url: 'http://localhost:65148/NewProfile/Genres',
                    dataType: 'json',
                    delay: 250,
                    data: function (params) {
                        return {
                            q: params.term, // search term
                            page: params.page
                        };
                    },
                    processResults: function (data, page) {
                        var newData = [];
                        $.each(data, function (index, item) {
                            newData.push({
                                id: item.Id,  //id part present in data 
                                text: item.Genre  //string to be displayed
                            });
                        });
                        return { results: newData };
                    },
                    cache: true
                },
                escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                minimumInputLength: 1
            });

@Html.DropDownListFor(x => x.BandProfile.Genres, Enumerable.Empty<SelectListItem>(), new { @class="genreOptions", multiple = "multiple", style ="width: 100%;"} )

The searching for tags works fine. But when I post the form, the count of the input field Is 0. How can I capture the data from the input form?

Copyright Notice:Content Author:「Bryan」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/36360512/use-jquery-select2-with-asp-net-mvc

More about “Use jQuery Select2 with ASP.NET MVC” related questions

Use jQuery Select2 with ASP.NET MVC

I'm trying to use Select2 in Razor in ASP.NET MVC. But I can't get work. $(document).ready(function () { $(&quot;.genreOptions&quot;).select2({ tags: true, ...

Show Detail

select2 not calling ajax action in my MVC application

I am using select2 in my ASP.NET MVC application for dropdown lists. Following are the version details: Select2 - 4.0.1-rc.1 jQuery - 2.1.0 BootStrap - 3.1.1 ASP.NET MVC 5 I have imported select...

Show Detail

How to use jquery Select2 in jtable

I just using jQuery jtable in mvc application, and use cascading dropdown, I want to use select2 in a dropdown, How can I use It?

Show Detail

select2 scroll to error not working with jquery validation and asp.net mvc

Posting this here in case someone else has the same problem... When using a select2 dropdown in a C# MVC4 site, the page is not scrolled to the correct position when validation fails. Validation a...

Show Detail

ASP.NET MVC Square Bracket Collection Model Binding

ASP.NET MVC's collection model binding requires square bracket indices in &lt;input /&gt; name attributes for collection models to be bound correctly, e.g. &lt;input name="Lines[0].Name" /&gt; with...

Show Detail

Filling Select2 Dropdown using ASP.net MVC4

I am trying to fill a dropdown which use Select2 Jquery add-on using asp.net mvc4. I have already search the stackoverflow and found the related topic as below ; Fill Select2 dropdown box from dat...

Show Detail

Select2 JQuery issue with ASP.NET UpdatePanel

Have a existing solution I have been asked to enhance with Select2 JQuery library. Have an updatepanel with a save button. On that updatepanel is a ASP.NET DropDownList. on document ready I issu...

Show Detail

What are the use cases for jQuery Templates in ASP.NET MVC?

For awhile now I have been looking for an overall data/markup strategy to settle into ASP.NET MVC, and am now currently looking at jQuery Templates. jQuery templates appear to me to be a new binding

Show Detail

set value to select2 which is retrive from database in ASP.NET MVC

i am using select2 control and i want to display or set value which i retrive from database how to set value to select2 which is retrive from database in ASP.NET MVC i am using select2 control and ...

Show Detail

How to use the select2 option in asp.net core?

I am working in asp.net core. I am using typescript. I want to use the Select2. How to use the select2 in asp.net core? Is there any package want to install for using select2?

Show Detail