telerik grid ajax,asp.net mvc - Telerik MVC Grid Ajax Parameters? - Stack Overflow

博主在尝试理解ASP.NET MVC中Telerik Ajax Grid参数配置时遇到困扰,发现参数设置似乎没有明显规律。文章探讨了是否需要在DataBinding中指定参数,以及何时可以依赖DataKeys中的参数。博主分享了一个示例代码,展示了如何为Grid绑定数据并传递参数到控制器,以根据JobID筛选数据。控制器方法接收JobID并返回对应的数据。尽管遇到了一些挑战,博主希望得到关于Ajax网格绑定和参数传递的简要指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am kind of fed up with trying to figure Ajax Grid parameters. I have created several grids and the parameters just kind of seem to be willy-nilly, I try one thing, it doesn't work for one, then works for another.

My understanding is that you really don't have to put the parameters in the .DataBinding if those parameters exist in the .DataKeys collection? This seems to be arbitrary when it works and when it doesn't.

Can someone give me a short overview about Ajax grid binding and passing parameters to a controller so I can select data to populate it with? Why is it I need to define the parameters and other times it works like magic?

Lately, every little think seems to be a battle with the Telerik MVC controls, even stuff I have done 5-6 times before.

In this case:

LineItemID is the primary key and JobID is a foreign key. I really want to pass the JobID to the select binding. I want to grab all line items with a specific JobID.

View:

@{ Grid grid = Html.Telerik().Grid()

.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 = "" })

.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("");

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())

Controller:

[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)));

}

Thanks in advance for any insight.

Steve

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值