首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何刷新mvc webgrid

如何刷新mvc webgrid
EN

Stack Overflow用户
提问于 2016-03-09 15:34:49
回答 1查看 10.1K关注 0票数 2

我在我的mvc应用程序中使用WebGrid。

代码语言:javascript
复制
<div class="grid-div" id="webgridid">
                @grid.GetHtml(
    tableStyle: "gridTable",
    headerStyle: "gridHead",
    footerStyle: "gridFooter",
    columns: new[]
    {
        grid.Column("name","Name", canSort: true, style: "name"),
        grid.Column("description","Description", canSort: true, style: "description"),
        grid.Column("duration","Duration", canSort: true, style: "duration"),
   })
</div>

我可以使用表单编辑选定的行值。编辑此值后,它不会反映在我的webGrid中。但它在DataBase中得到了反映。为了将这一点反映到webGrid中,我需要通过从DB加载数据来刷新webGrid。如何将内容从DB重新加载到webGrid?另外,在重新加载之后,这个pageNumber应该是旧的。该怎么做呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-09 17:55:39

最后,我找到了解决问题的办法。我必须用ID定义一个<div>,并在WebGrid控件的ajaxUpdateContainerId属性中引用divid,这将允许WebGrid使用Ajax异步更新数据。

代码语言:javascript
复制
<div id="ajaxgrid">
  @{
      var grid = new WebGrid(Model, rowsPerPage: 10, selectionFieldName: "SelectedRow", ajaxUpdateContainerId: "ajaxgrid");                   
   }
</div>

然后调用WebGridGetHtml方法,以便Razor引擎可以为其生成相应的HTML。在<div>标签的末尾。

代码语言:javascript
复制
@grid.GetHtml(
    tableStyle: "gridTable",
    headerStyle: "gridHead",
    footerStyle: "gridFooter",
    columns: new[]
    {
        grid.Column("name","Name", canSort: true, style: "name"),
        grid.Column("description","Description", canSort: true, style: "description"),
        grid.Column("duration","Duration", canSort: true, style: "duration"),
   })

然后,在我的ajax更新调用中,我添加了location.reload()来刷新我的WebGrid

代码语言:javascript
复制
$.ajax({
                url: '@Url.Action("User", "UserDetails")',
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: formData,
                contentType: false,
                processData: false,
                success: function (result) {
                    if (result == "OK") {
                        location.reload();
                    }
                    else
                        alert(result);
                },
                error: function (result) {
                    alert('Error!');
                }
            });

现在它对我来说工作得很好。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35885586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档