Unknown web method . Parameter name: methodName
Estaba realizando unas pruebas para poder llamar a un WebMethod, desde jQuery, pero cada que debía ser invocado obtenía el siguiente error:
Unknown web method agregarRegistroGrid . Parameter name: methodName
El llamado desde jQuery estába así:
$.ajax({
type: "POST",
url: "Venta.aspx/agregarRegistroGrid",
data: JSON.stringify(
{
'id': $("#divIdProducto").html(),
'cantidad': $('#txtCantidad').val(),
'nombreProducto': $("#divTituloProducto").text(),
'pUnitario': $('#txtPrecio').val(),
'importe': $('#txtPrecio').val()
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
error: function (x, e) {
var not2 = $.Notify({ style: { background: 'red', color: 'white' }, caption: 'Error.', content: x.responseText });
}
})
Y mi WebMethod estaba así:
[WebMethod]
private void agregarRegistroGrid(int id, int cantidad, string nombreProducto, string pUnitario, string importe)
{
Venta vta = new Venta();
DataRow dr = vta.dt.NewRow();
dr[“id”] = id;
dr[“cantidad”] = cantidad;
dr[“nombre”] = nombreProducto;
dr[“pUnitario”] = pUnitario;
dr[“importe”] = importe;
vta.dt.Rows.Add(dr);
vta.BindGrid();
}
La solución resultó muy sencilla, y fue cambiar de esto: