我正在尝试学习如何在MVC3中使用Razor WebGrid。 ajaxUpdateCallback 参数如何工作?
答案 0 :(得分:46)
ajaxUpdateCallback是服务器调用完成后将调用的javascript函数的名称。您的问题的标题是关于使用WebGrid进行分页和排序,看起来像这样......
@{
var grid = new WebGrid(canPage: true, rowsPerPage: ThisController.PageSize, canSort: true, ajaxUpdateContainerId: "grid");
grid.Bind(Model.Employees, rowCount: Model.TotalRecords, autoSortAndPage: false);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(htmlAttributes: new { id="grid" },
columns: grid.Columns(
grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { EmployeeID = item.EmployeeID })),
grid.Column("FullName"),
grid.Column("Title")
));
}
如果你想看到它,我在这里有一个完整的例子:
答案 1 :(得分:15)
ajaxUpdateCallBack参数用于指定当ajaxUpdateContainerId值表示的元素由于排序或分页等而更新时应该调用的JavaScript函数。将它传递给构造函数,如下所示:
var grid = new WebGrid(data, ajaxUpdateContainerId : "grid",
ajaxUpdateCallback: "callBack");
它将指向:
function callBack(){
alert('Called Back');
}