Kendo grid DataSourceRequest将数值过滤器解析为double

时间:2017-11-13 10:31:36

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

我正在使用Kendo MVC网格,在过滤long类型的列时,传递给DataSourceRequest.Filters下的控制器操作的值的类型为double。这导致我出现问题,因为我正在为ORM动态构建过滤条件,并且无法隐式地将double转换为long

查看型号:

public class AttendeeViewModel
{
    public long Id { get; set; }
    public long BookingId { get; set; }
}

缩小网格初始化:

@(Html.Kendo().Grid<AttendeeViewModel>()
  .Name("Grid")
  .EnableCustomBinding(true)
  .DataSource(ds => ds
    .Ajax()
    .Read(r => r.Action("Grid_Read", "AttendeeController"))
    .Model(m =>
    {
        m.Id(x => x.Id);
        m.Field("Id", typeof(long));        // These type definitions don't
        m.Field("BookingId", typeof(long)); // seem to make a difference
    })
    .ServerOperation(true)
  )
  .Columns(c =>
  {
    c.Bound(m => m.BookingId)
        .Title("Booking ID")
        // Using the UI method from another question to prevent decimal places in filter
        .Filterable(ftb => ftb.Cell(cell => cell.Operator("eq")
          .ShowOperators(false))
          .UI("gridNumericFilter"));
    c.Bound(m => m.Id)
        .Title("Attendee ID")
        .Filterable(ftb => ftb.Cell(cell => cell.Operator("eq")
          .ShowOperators(false))
          .UI("gridNumericFilter"));
  })
  .Filterable(f =>
  {
    f.Mode(GridFilterMode.Row);
    f.Extra(false);
  })
)

过滤后,以下HTTP查询字符串将发送到控制器方法:

?page=1&pageSize=20&group=&filter=Id~eq~30622

签名:

public ActionResult Grid_Read([DataSourceRequest] DataSourceRequest request) {...}

由于某种原因,将过滤器解析为double:

((Kendo.Mvc.FilterDescriptor)request.Filters[0]).Value.GetType().Name
"Double"

如何让DataSourceRequest解析正确的属性类型 - long而不是double

0 个答案:

没有答案