【问题标题】:WebGrid not refreshing inside Partial ViewWebGrid 在局部视图中不刷新
【发布时间】:2019-10-24 16:11:02
【问题描述】:

我在部分视图中有一个 WebGrid,如下所示:

<div class="box box-primary" id="gridSharedPractice">
    <div class="box-header with-border col-sm-12">
        <h3 class="box-title" id="PracticeAreasSharedHeading" name="ShareTemplateHeading">Practice Areas Shared </h3>
    </div>
<div class="box-body">
    <div id="PracticeGrid">
        @{
            var TestModel = Model.STAllPractice;
            var grid3 = new WebGrid(TestModel as IEnumerable<ASP_Upload_Version_1.Models.Share_Template>, canPage: false, canSort: false, ajaxUpdateContainerId: "PracticeGrid");
        }
    </div>

        @grid3.GetHtml(tableStyle: "table table-sm table-striped table-condensed",
                          htmlAttributes: new { @id = "GridSharedPractice", @class = "table table-sm table-striped table-bordered table-condensed", @style = "width:100%" },
                          columns: grid3.Columns(
                             grid3.Column("ShareID", "Share ID", null, "hidden-column"),
                             grid3.Column("TemplateName", "Template Name"),
                             grid3.Column("PracticeAreaAll", "Practice Area"),
                             grid3.Column(format: @<text>
                                    <a data-title="Are you sure to deactivate this Input?" onclick="DeleteRow(@item.ShareID)" class="delete"><i class="fa fa-trash" style="color:red"></i></a></text>, header: "Remove")));

</div>  
</div>

以及从 webgrid 中删除任何行的 ajax 调用。

    function DeleteRow(ShareID) {
        $.ajax({
            url: '/ShareTemplate/UnShare/',
            data: "{ 'Type': 'Practice','ShareID': '" + ShareID + "'}",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                alert(data);
                $('#GridSharedPractice').html(data);                
                alert("disnt bind");
            },
            error: function (response) {
                //alert(response.responseText);
            },
            failure: function (response) {
                //alert(response.responseText);
            }
        });
    }

</script>

删除部分工作正常,但删除后,我无法刷新 WebGrid。

这是在主视图中调用局部视图的方式:

@{Html.RenderAction("PracticeGridPartialView", "ShareTemplate");}

【问题讨论】:

    标签: c# .net model-view-controller partial-views webgrid


    【解决方案1】:

    您可以在 ajax 调用中使用它来加载部分视图

    success: function (data) {
                    $('#PartialGridsPractice').load('/<Controller>/<Action returning Partial View>');
                },
    

    【讨论】:

      猜你喜欢
      • 2017-10-10
      • 2014-08-20
      • 2016-02-07
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      相关资源
      最近更新 更多