I am getting “Loading failed” error when I type characters in select2 textbox
-
i work with mvc , c# on visual studio 2015 community
-
code source in .cshtml
to show textbox : @Html.Hidden(“cod_indem”)
to apply select2 on this object (“cod_indem”) :$(function () {
$("#cod_indem").select2(
{
width: “100%”,
ajax: {
type: “Get”,url: '@(Url.Action("GetAll", "Zpy_paye"))', cache: false, dataType: 'json', delay: 250, data: function (term, page) { return { match: term, // search term pageIndex: page, pageSize: 30 }; }, results: function (data, page) { page = page || 1; return { results: data.items, more: (page * 30) < data.total_count }; } }, escapeMarkup: function (markup) { return markup; }, minimumInputLength: 3, formatSelection: format, formatResult: format });
});
function format(data) {
return data.text;}
///------- code of Select2DTO.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcPagingDemo.Models
{
public class Select2DTO
{
public Guid id { get; set; }
public string Code { get; set; }
public string text { get; set; }
}
}
///------- code of Select2Result.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcPagingDemo.Models
{
public class Select2Result
{
public List items { get; set; }
public int total_count { get; set; }
}
}
///------- in controller :
public Select2Result GetAll(string match, int pageIndex = 1, int pageSize = 30)
{
int totalCount;
if (pageIndex <= 0) pageIndex = 1;
if (pageSize >= 30) pageSize = 30;
var zpy_indemnites = Get_All_indemnite_FilteredPaged(match, out totalCount, pageIndex - 1, pageSize);
var zpy_indemnitesDTO = (from a in zpy_indemnites
select new Select2DTO { id = a.id , Code = "sss", text = a.des_f }).ToList();
return new Select2Result { items = zpy_indemnitesDTO, total_count = totalCount };
}
//---------------------------------------------------
[HttpGet]
public List<zpy_indemnite> Get_All_indemnite_FilteredPaged(string match, out int totalCount, int pageIndex = 0, int pageSize = 10)
{
grh_paie_Entities context = new grh_paie_Entities();
context = ContextManager.Context;
var query = context.zpy_indemnite.AsQueryable();
//TODO: Check if the match parameter is not null or empty and add the necessary where condition.
if (!string.IsNullOrEmpty(match))
query = query.Where(c => c.des_f.Contains(match) );
//TODO: Set the totalCount to the Total Count of zpy_indemnite in the Data Store.
totalCount = query.Count();
//TODO : Get the list of communes paged use the Skip and Take LINQ extension methods.
var zpy_indemnites = query.OrderBy(c => c.des_f)
.Skip(pageIndex * pageSize)
.Take(pageSize)
.ToList();
return zpy_indemnites;
}
please i need a help