Telerik MVC网格Ajax参数



我有点厌倦了试图计算Ajax Grid参数。我已经创建了几个网格和参数似乎是不情愿的,我尝试了一件事,它不适合一个,然后对另一个工作。

我的理解是,如果这些参数存在于。datakeys集合中,你真的不必把参数放在。databinding中?这似乎是任意的,当它工作时,当它不工作。

有人能给我一个简短的概述关于Ajax网格绑定和传递参数到一个控制器,所以我可以选择数据来填充它?为什么我需要定义参数,而其他时候它就像魔法一样工作?

最近,每一点想法似乎都是与Telerik MVC控件的战斗,甚至是我以前做过5-6次的东西。

在这种情况下:LineItemID是主键,JobID是外键。我真的希望将JobID传递给选择绑定。我想抓取具有特定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)));
}

提前感谢任何见解。史蒂夫。

在Teleriks论坛上看到一个类似的问题。我使用OnDataBinding事件,如本文所述:关于从AJAX绑定调用向控制器传递参数。

适合我。使用Telerik扩展2012第二季度。

尝试指定. routekey ("someName")为每个dataKey,你想(需要)自动获得控制器上,"someName"应该是相同的动作参数名称。

最新更新