在 Kendo Grid 读取操作中发送附加参数 [英] Send Additional Parameter in Kendo Grid Read Action
本文介绍了在 Kendo Grid 读取操作中发送附加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个剑道网格如下.
I have a kendo Grid as follows.
@(Html.Kendo().Grid<RevenueModel>()
.Name("WeeklyRevenue")
.Resizable(resizing => resizing.Columns(true))
.Columns(columns =>
{
columns.Bound(p => p.Number).Width(100);
columns.Bound(p => p.Type).Width(100);
columns.Bound(p => p.Week1).Format("{0:c}");
columns.Bound(p => p.Week2).Format("{0:c}");
columns.Bound(p => p.Week3).Format("{0:c}");
columns.Bound(p => p.Week4).Format("{0:c}");
columns.Bound(p => p.Week5).Format("{0:c}");
columns.Bound(p => p.TotalRevenue).Format("{0:c}");
})
.Scrollable()
.Events(events => events.Change("onChange").DataBound("onDataBound"))
.DataSource(dataSource => dataSource.Ajax().Read(read => read.Action("WeeklyRevenue", "Home")).ServerOperation(false))
.Pageable(pager => pager.Refresh(true))
)
这是我的控制器代码
public ActionResult WeeklyRevenue([DataSourceRequest]DataSourceRequest request)
{
...
DataSourceResult result = res.ToDataSourceResult(request);
return Json(result, JsonRequestBehavior.AllowGet);
}
它工作正常.但是我想在 Grid 读取数据时发送额外的数据,如下所示;
It works fine. But I want to send additional data when Grid reads data, something like the following;
public ActionResult WeeklyRevenue([DataSourceRequest]DataSourceRequest request, string AdditionalParam)
我找不到任何解决方法.提前致谢.
I couldn't find any solution how to do this. Thanks in advance.
推荐答案
如果额外的数据在服务器端是已知的,你应该使用接受路由值的 Action 方法的重载:
If the additional data is known at server-side you should use the overload of the Action method which accepts route values:
.DataSource(dataSource => dataSource.Server()
.Read(read => read.Action("Read", "Home",
new { AdditionalParam = ViewData["AdditionalParam"] }))
)
如果只有客户端知道这些额外数据,您应该使用 Data 方法:
If this additional data is known at the client-side only you should use the Data method:
.DataSource(dataSource => dataSource.Ajax()
.Read(read => read
.Action("Read", "Home")
.Data("additionalData")
)
)
<script>
function additionalData() {
return {
AdditionalParam: $("#search").val()
};
}
</script>
这篇关于在 Kendo Grid 读取操作中发送附加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文