Posts

Showing posts from September, 2021

https://manhng.com/blog/mvc5-select2/

Image
ASP.NET MVC using Select2 June 4, 2020 10:49 ASP.NET MVC using Select2 ( edit ) https://blog.e-zest.com/tech-tutorial-select2-with-asp.net-mvc Why Select2: Using this jQuery plugin for dropdown lists, you can implement features such as option grouping, searching, infinite scrolling, tagging, remote data sets and other highly used features. To use select2 in web projects, you just have to include JavaScript and CSS files of Select2 in your website. Current version of select2 is 4.0.0. You can easily include these files by installation of NuGet package ‘Select2.js’ from NuGet package manager. You can see examples of Select2   here . Steps of Implementation: 1. Create a blank ASP.NET MVC project, and install NuGet packages Select2.js, jQuery and jQuery Unobtrusive. 2. Add one controller with the name ‘HomeController’ and add view for default method ‘Index’. 3. Create new class in Models folder ‘IndexViewModel.cs as shown below: public class IndexViewModel {    [Required(ErrorMessage="

Ajax (remote data)

  Ajax (remote data) Select2 comes with AJAX support built in, using jQuery's AJAX methods. In this example, we can search for repositories using GitHub's API: Search for a repository In your HTML: < select class = "js-data-example-ajax" ></ select > In your Javascript: $( '.js-data-example-ajax' ).select2({ ajax: { url: 'https://api.github.com/search/repositories' , dataType: 'json' // Additional AJAX parameters go here; see the end of this chapter for the full code of this example } }); You can configure how Select2 searches for remote data using the  ajax  option. Select2 will pass any options in the  ajax  object to jQuery's  $.ajax  function, or the  transport  function you specify. For  remote data sources only , Select2 does not create a new  <option>  element until the item has been selected for the first time. This is done for performance reasons. Once an  <option>  has been created,