WebGrid在部分视图中未刷新

时间:2019-06-10 09:00:32

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

我在Partial View中有一个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>

和ajax调用以从Webgrid删除任何行。     

    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");}

1 个答案:

答案 0 :(得分:2)

您可以在ajax调用中使用它来加载Partial View

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