在PartialView中使用Kendo Grid [英] Using Kendo Grid in PartialView

查看:48
本文介绍了在PartialView中使用Kendo Grid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MVC应用程序的索引"视图中有两个<section>,我想在这些部分中呈现两个局部视图.将Kendo网格渲染到一个索引没有问题.但是,为了在Kendo Grid上渲染数据,我可以使用两种方法在控制器中返回Json,如下所示.您能举个例子如何实现这一目标吗?

I have two <section> in the Index view of my MVC application and I want to render two partial views in these sections. There is no problem rendering a Kendo grid to one Index. However, in order to render data on Kendo Grid, could I use the two methods returning Json in the controller as shown below. Could you give me an example how to achieve this?

控制器:

public ActionResult Index()
{
    return View();
}

public ActionResult Issues_Read([DataSourceRequest]DataSourceRequest request)
{
    IQueryable<Issue> issues = db.Issues;
    DataSourceResult result = issues.ToDataSourceResult(request, c => new IssueViewModel 
    {
        ID = c.ID,
        ProjectID = c.ProjectID
    });

    return Json(result);
}


查看:

@(Html.Kendo().Grid<IssueViewModel>()
  .Name("grid")
  .Columns(columns =>
  {
      columns.Bound(c => c.ProjectID);
      columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180);
  })
  .ColumnMenu()
  .Editable(editable => editable.Mode(GridEditMode.PopUp))
  .Pageable()
  .Navigatable()    
  .DataSource(dataSource => dataSource
      .Ajax()
      .Model(model => model.Id(p => p.ID))
      .Read(read => read.Action("Issues_Read", "Issue"))
      .Create(create => create.Action("Issues_Create", "Issue" ))
      .Update(update => update.Action("Issues_Update", "Issue"))
      .Destroy(destroy => destroy.Action("Issues_Destroy", "Issue"))
  )
)

推荐答案

为了多次使用相同的局部视图,网格ID应该是唯一的,因此在局部视图数据中传递ID是一种可能的解决方案.在你的情况下 部分视图首次调用:

In order to use the same partial view multiple times, grid ID should be unique so passing the ID in partial view data is one possible solution. In your case Partial view first call:

@Html.Partial("grid", new ViewDataDictionary { { "id", "grid1" }})

部分查看第二次通话:

@Html.Partial("grid", new ViewDataDictionary { { "id", "grid2" }})

部分视图内容:

@(Html.Kendo().Grid<IssueViewModel>()
  .Name(@ViewData["id"].ToString())
...

这篇关于在PartialView中使用Kendo Grid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆