Usuario
Select2 en Asp.net Framewrok 4.0

Pregunta
-
Hola tengo dias con este tema y no puedo solucionarlo estoy usando la libreria select2 para hacer busquedas remotas, vi un ejemplo en youtube y trato de duplicarlo, pero no puedo, en la consola no me aparece ningun error, solo el componente me dice "fallo en carga" y lo mas extraño cuando trato de debuggear del lado del server nunca viaja hacia alla, aqui esta mi codigo
<script>
$(document).ready(function () {
$("#cmbselect").select2({
minimumInputLength: 1,
placeholder: "Seleccione un cliente",
allowClear: true,
ajax: {
url: "Select2Remote.aspx/getClient",
dataType: 'json',
type: 'POST',
params: {
contentType: 'application/json; charset=utf-8'
},
data: function (term, page) {
return JSON.stringify({ q: term, page_limit: 10 });
},
processResults: function (data, params) {
params.page = params.page || 1;
return {
results: data.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
}
},
escapeMarkup: function (markup) { return markup; },
templateResult: formatState
});
});
function formatState(cliente) {
if (!cliente.id) { return cliente.text; }
var $state = $('<span>' + cliente.text + '</span>');
return $state;
};
</script>//servidor es la misma hoja
using ClassLibraryEntidades.JSON;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication_Dali_SICED.Handler.Expedientes
{
public partial class Select2Remote : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<clejsonCliente> getClient(string q, string page_limit)
{
List<clejsonCliente> ListaClientes = new List<clejsonCliente>();
clejsonCliente clejsonClienteJilmar = new clejsonCliente
{
NombreCliente = "Jilmar",
Id = 1,
RFC = "RAG"
};
clejsonCliente clejsonClientePedro = new clejsonCliente
{
NombreCliente = "Pedro",
Id = 1,
RFC = "Chavez"
};
ListaClientes.Add(clejsonClienteJilmar);
ListaClientes.Add(clejsonClientePedro);
return ListaClientes;
}
}
}Gracias
Todas las respuestas
-
hola
Si inspeccionas la Developer Tools del browser, a la cual accedes con F12, puedes visualizar algun error en la invocacion al servicio
valida las solapas "console" y "network" ya que alli tendras datos de como fue invocado el servicio
Ademas intenta usando
data: function (term, page) {
return { q: term, page_limit: 10 };
}ya que defiens el dataType como json deberia poder entender directo sin convertir a string
saludos
Leandro Tuttini
Blog
MVP Profile
Buenos Aires
Argentina -