【问题标题】:Refresh Kendo grid on PartialViewResult update在 PartialViewResult 更新上刷新 Kendo 网格
【发布时间】:2016-01-07 18:36:45
【问题描述】:

我认为我有一个 Ajax 表单。 以及在视图内的局部视图中呈现的 Kendo 网格。

@using (Ajax.BeginForm("AddToCatalogue", "Home", new AjaxOptions { UpdateTargetId = "catalogueSummary", InsertionMode = InsertionMode.Replace }, new { id = "addToCatalogueForm" }))
{
    <input type="submit" class="button radius hide" id="btnAdd" value="Add to Catalogue" />
}

@Html.Partial("~/Views/Home/_CatalogueSummary.cshtml", Model.CatalogueItem)

在部分我有网格:

@使用 Web.Models @model IEnumerable

<div class="row">
    <div class="panel">
        <h5>Summary</h5>
        <div id="divGrid">
            @(Html.Kendo().Grid(Model)
                .Name("catalogueSummaryGrid")
                .Columns(columns =>
                {
                    columns.Bound(c => c.Name);
                    columns.Bound(c => c.Length);
                    columns.Bound(c => c.Description);
                    columns.Bound(c => c.Ref);
                })
                .Sortable()
                .DataSource(dataSource => dataSource
                .Ajax()
                .Group(groups => groups.Add(p => p.Type))
                .ServerOperation(false))
            )
        </div>
    </div>
</div>

所以我从主要部分的部分外部触发更新,调用操作:

    [HttpPost]
    public PartialViewResult AddToCatalogue()
    {
        // Get the current state of this catalogue
        var api = new ServerApi<WebCatalogue>();
        var webCatalogue = api.GetRequest("WebCatalogue").Result;

        // Set up the UX state
        var catalogueItems = new List<CatalogueItem>();

        // Begin with existing items prior to this post
     catalogueItems.AddRange(JsonConvert.DeserializeObject<List<CatalogueItem>>(webCatalogue.Data));

        // Add in the dummy item
        var newItem = new CatalogueItem()
            {
            Type= "Single",
            Name = "Mark",
            Length = 5,
            Description = "some desc",
            Ref = "Ref 1"
            };
        catalogueItems.Add(CatalogueItem);

        // Apply the new UX state to the WebCatalogue and post it to the web api method
        var newItems = JsonConvert.SerializeObject(catalogueItems);
        webCatalogue.Data = newItems;
        api.PostRequest("WebCatalogue", webCatalogue);

        // Return the refreshed view
        return this.PartialView("_CatalogueSummary", catalogueItems);
    }

【问题讨论】:

    标签: asp.net-mvc kendo-grid refresh kendo-asp.net-mvc asp.net-mvc-partialview


    【解决方案1】:

    有趣的是,有时通过在这里写一个问题,我开始分析我的代码比搜索错误要深入得多(即使我在这里发布任何内容之前都非常仔细地分析了它),只有在发布问题之后我才意识到问题是。

    在这种情况下,我错过了 id = "catalogueSummary" 的 div,它必须在 ajax 表单发布时更新。

    添加解决了问题哈!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 2014-03-18
      • 2014-03-26
      • 2017-06-10
      • 2014-06-10
      • 2019-01-06
      • 2015-03-28
      相关资源
      最近更新 更多