为什么控制器方法充当POST而不是GET?

时间:2016-01-14 19:55:04

标签: c# asp.net-mvc kendo-grid

我有一个 kendoGrid ,用.Read(r => r.Action("CargaNotificacionesPorCliente", "bff").Data("getClaveCliente")))读取数据,调用正常,网格中的值正确显示,这里没什么奇怪的。

kendoGrid

当我打开Chrome DevTools时,它会显示以下错误:

  

POST http://localhost:52881/bff/CargaNotificacionesPorCliente 500   (内部服务器错误)

我不知道为什么将其标记为 POST 而非 GET

这是我的方法(实际上有效)

public ActionResult CargaNotificacionesPorCliente([DataSourceRequest] DataSourceRequest request, string numeroCliente)
{
    bff.Configuration.LazyLoadingEnabled = false;

    var lstNotificaciones = new List<NotificacionesModel>();

    var lstNoPartesNuevas = bff.inspListaNoPartes
        .Where(x => x.codeCustomer == numeroCliente &&
                    x.Estatus == Constantes.EstatusNumParteNuevo &&
                    x.VistoCte == false)
        .Include(i => i.CustomerCUSTOMER)
        .ToList();

    var cantidadComentariosNuevos = bff.inspCommentNoPartes
        .Count(x => x.inspListaNoParte.codeCustomer == numeroCliente &&
                    x.Visto == false &&
                    x.Usuario != User.Identity.Name);

    if (lstNoPartesNuevas.Any())
    {
        foreach (var item in lstNoPartesNuevas)
        {
            if (lstNotificaciones.All(a => a.IdCustomer != item.IdCustomer))
            {
                lstNotificaciones.Add(new NotificacionesModel
                {
                    Cantidad = lstNoPartesNuevas.Count(x => x.IdCustomer == item.IdCustomer && x.Estatus == Constantes.EstatusNumParteNuevo && x.VistoSup == false) + cantidadComentariosNuevos,
                    Name = item.CustomerCUSTOMER.name,
                    IdCustomer = item.IdCustomer,
                    IdNumPart = item.IdNumPart
                });
            }
        }
    }
    return Json(lstNotificaciones.ToList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

这是DevTools

中错误的预览标签
  

&#39; /&#39;中的服务器错误应用

     

输入字符串的格式不正确。

     

描述:执行期间发生了未处理的异常   当前的网络请求。请查看堆栈跟踪了解更多信息   有关错误的信息以及它在代码中的起源。

     

异常详细信息: System.FormatException:输入字符串不在   格式正确。

但正如我所说,它很奇怪,因为它有效

尝试添加 [HttpGet] 但是不起作用,实际上永远不会使用该注释调用该方法。

修改

我通过这种方式做了绑定:

$("#Notificaciones").data("kendoGrid").dataSource.read(); // Read data
$("#Notificaciones").data("kendoGrid").dataSource.page(1); // Go to page 1

我删除了第二行(.dataSource.page(1);),现在错误消失了,但是这会如何影响通话?我无法弄清楚

2 个答案:

答案 0 :(得分:1)

应该可以做这样的事情

.DataSource(dataSource => dataSource
.Ajax()
    .Read(read => read.Action("Index", "Banques").Type(HttpVerbs.Get))
.PageSize(8)
)

http://www.telerik.com/forums/post-vs-get-request

答案 1 :(得分:1)

在您使用的工具中,确保将HTTP谓词选为Get。请参阅下面的Chrome's Postman截图 enter image description here

相关问题