我正在使用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
?