Ajax 在一次调用中将 Telerik MVC Grid 与 DetailView 绑定

发布于 2024-12-13 18:30:30 字数 2372 浏览 2 评论 0原文

我有以下标记。

@(Html.Telerik().Grid(Model)
         .Name("Grid")
         .DataKeys(keys => keys.Add(key => key.Id))
         .Columns(columns =>
                      {
                          columns.Bound(c => c.FullNameWithEmail).ClientTemplate("<#= FullNameWithEmail #>").Title("Name and Email").Width(230);
                          columns.Bound(c => c.Notes);
                      })
         .ClientEvents(events => events.OnRowDataBound("grid_onRowDataBound"))
         .DetailView(checkInAppGridDetails => checkInAppGridDetails.ClientTemplate("<# if (RelatedCount > 0) { #>" +

              Html.Telerik().Grid<ViewModel>()
                                      .Name("GridDetails_<#= Id #>")
                                      .Footer(false)
                                      .Columns(columns =>
                                      {
                                          columns.Bound(c => c.FullNameWithEmail).ClientTemplate("<#= FullNameWithEmail #>").Title("Name and Email").Width(225);
                                          columns.Bound(c => c.Notes);
                                          columns.Bound(c => c.Actions).ClientTemplate("<#= Actions #>").Width(150);
                                      })
                                      .ClientEvents(events => events.OnRowDataBound("GridDetails_onRowDataBound"))
                                      .DataBinding(dataBinding => dataBinding.Ajax()
                                          .Select("GetRelated", "Controller", new
                                          {
                                              id = @ViewBag.EventKey,
                                              ticketId = "<#= Id #>"
                                          }))
                                      .ToHtmlString() +
              "<# } #>"
          ))
  )

我这里所拥有的是,我使用 Ajax 调用绑定主网格,一旦绑定了行,详细信息视图就会与 DataBinding ajax 调用绑定。

我已经在模型中包含了我想在 DetailView 中显示的相关记录的集合,我不希望对服务器进行额外的调用。

这是 ViewModel 的示例

public class ViewModel
{
    public string FirstProperty {get; set;}
    .
    .
    .
    public IEnumurable<ViewModel> RelatedRecords { get; set; }
}

您知道如何仅通过单个 Ajax 请求将整个 Grid 与 DetailView 绑定吗?

I have the following markup.

@(Html.Telerik().Grid(Model)
         .Name("Grid")
         .DataKeys(keys => keys.Add(key => key.Id))
         .Columns(columns =>
                      {
                          columns.Bound(c => c.FullNameWithEmail).ClientTemplate("<#= FullNameWithEmail #>").Title("Name and Email").Width(230);
                          columns.Bound(c => c.Notes);
                      })
         .ClientEvents(events => events.OnRowDataBound("grid_onRowDataBound"))
         .DetailView(checkInAppGridDetails => checkInAppGridDetails.ClientTemplate("<# if (RelatedCount > 0) { #>" +

              Html.Telerik().Grid<ViewModel>()
                                      .Name("GridDetails_<#= Id #>")
                                      .Footer(false)
                                      .Columns(columns =>
                                      {
                                          columns.Bound(c => c.FullNameWithEmail).ClientTemplate("<#= FullNameWithEmail #>").Title("Name and Email").Width(225);
                                          columns.Bound(c => c.Notes);
                                          columns.Bound(c => c.Actions).ClientTemplate("<#= Actions #>").Width(150);
                                      })
                                      .ClientEvents(events => events.OnRowDataBound("GridDetails_onRowDataBound"))
                                      .DataBinding(dataBinding => dataBinding.Ajax()
                                          .Select("GetRelated", "Controller", new
                                          {
                                              id = @ViewBag.EventKey,
                                              ticketId = "<#= Id #>"
                                          }))
                                      .ToHtmlString() +
              "<# } #>"
          ))
  )

What i have here is that i am binding the main grid with Ajax call, and once rows got bound the details view gets bound with the DataBinding ajax call.

I already have in the Model a collection for the related records i wanted to show in the DetailView, i don't want the extra call to the server.

here is an example of the ViewModel

public class ViewModel
{
    public string FirstProperty {get; set;}
    .
    .
    .
    public IEnumurable<ViewModel> RelatedRecords { get; set; }
}

Any idea how to bind the whole Grid with the DetailView with only single Ajax request?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一萌ing 2024-12-20 18:30:30

刚刚使用 telerik 支持示例来解决此问题,效果非常好。 with-detailview-in-one-call.aspx" rel="nofollow">Telerik 帖子

Just used telerik support example to fix this, and it worked very well.Telerik Post

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文