【发布时间】:2011-09-24 20:16:04
【问题描述】:
我有点厌倦了试图计算 Ajax Grid 参数。我创建了几个网格,参数似乎是随意的,我尝试一件事,它对一个不起作用,然后对另一个起作用。
我的理解是,如果这些参数存在于 .DataKeys 集合中,您真的不必将这些参数放在 .DataBinding 中吗?这似乎是任意的,什么时候起作用,什么时候不起作用。
谁能给我一个关于 Ajax 网格绑定和将参数传递给控制器的简短概述,以便我可以选择数据来填充它?为什么我需要定义参数,而其他时候它就像魔术一样工作?
最近,每一个小小的想法似乎都是与 Telerik MVC 控件的一场战斗,甚至是我之前做过 5-6 次的事情。
在这种情况下: LineItemID 是主键,JobID 是外键。我真的很想将 JobID 传递给 select 绑定。我想获取具有特定 JobID 的所有订单项。
查看:
@{ Grid<viaLanguage.Jams.Data.tblJobManagementLineItem> grid = Html.Telerik().Grid<viaLanguage.Jams.Data.tblJobManagementLineItem>()
.Name("InvoiceLineItemsGrid")
.DataKeys(keys =>
{
keys.Add(i => i.LineItemID);//.RouteKey("LineItemID");
keys.Add(i => i.JobID);//.RouteKey("jobID");
})
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("_SelectInvoiceLineItems", "Job", new { jobID = "<#= JobID #>" })
.Insert("_InsertJobInvoice", "Job")
.Update("_UpdateJobInvoice", "Job")
.Delete("_DeleteJobInvoice", "Job"))
.ToolBar(commands => commands.Insert().HtmlAttributes(new { style = "margin-left:0" }))
.Columns(columns =>
{
columns.Bound(l => l.JobID);
columns.Bound(l => l.LineItemDescr).Width(180).HeaderTemplate("Task");
columns.Bound(l => l.LanguagePairID).Width(100).HeaderTemplate("Language Pair").ClientTemplate("<#= LanguagePair #>");
columns.Bound(l => l.SourceWordCount).Width(100).HeaderTemplate("Source Words");
columns.Bound(l => l.QtyToInvoice).Width(100).HeaderTemplate("Quantity to Invoice");
columns.Bound(l => l.Rate).Width(50).Format("${0:0.000}").HeaderHtmlAttributes(new { style = "text-align: center;" }).HtmlAttributes(new { style = "text-align: center;" });
columns.Bound(l => l.SubTotal).Width(100).Format("{0:c}");
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Image);
commands.Delete().ButtonType(GridButtonType.Image);
}).Width(80).HtmlAttributes(new { style = "white-space: nowrap;" });
})
.Resizable(resizing => resizing.Columns(true))
.Sortable()
.Selectable()
.Pageable(paging => paging.PageSize(10))
.Scrollable(c => c.Height("233px"))
.Filterable();
StringWriter sw = new StringWriter();
grid.Render();
grid.WriteInitializationScript(sw);
}
@Html.Hidden("InvoiceLineItemsGrid_tGrid", sw.GetStringBuilder().ToString())
控制器:
[GridAction]
public ActionResult _SelectInvoiceLineItems(int jobID)
{
logLogic.logger.Debug(logLogic.GetMethodName() + ": User '" + User.Identity.Name);
return View(new GridModel(jobLogic.GetInvoiceLineItems(jobID, User.Identity.Name)));
}
提前感谢您提供任何见解。 史蒂夫
【问题讨论】:
-
什么不起作用?参数是 null 还是空字符串之类的?还是您遇到了一些错误?
-
是的,马特是对的,您需要更具体一些。您在控制器操作中收到的值是什么。由于您正在使用分页,因此请尝试确定该请求是否适用于第一页,并在您转到另一页时停止工作。此外,您在操作方法中接收到错误的值一定存在某种模式。
标签: asp.net-mvc ajax telerik-grid telerik-mvc