在PartialViewResult更新

时间:2015-07-16 11:32:53

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

我的视图中有一个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)

在部分我有网格:

@using 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);
    }

1 个答案:

答案 0 :(得分:0)

有趣的是,有时候通过在这里写一个问题我开始分析我的代码比我搜索错误更深入(即使我在发布任何内容之前仔细分析它),只有在发布问题之后才知道什么是问题是。

在这种情况下,我错过了id =&#34; catalogueSummary&#34;必须在ajax表格上更新。

添加解决问题ha!