1

我在网格设置中有这个:

    var gridLayoutRepository = new GridLayoutRepository();

    settings.ClientLayout = (s, e) =>
    {
        Debug.Write(e.LayoutData);

        if (e.LayoutMode == ClientLayoutMode.Loading)
        {
            e.LayoutData = gridLayoutRepository.Load();
        }
        else
        {
            gridLayoutRepository.Save(e.LayoutData);
        }
    };

我想要一个按钮用于在数据库中保存网格状态,一个按钮用于重置它。你能帮助我吗?

4

1 回答 1

1

这种方式是可能的。在网格设置中必须保存网格状态:

settings.ClientLayout = (s, e) =>
    {
        if (e.LayoutMode == ClientLayoutMode.Loading)
        {
            if (Session["myGridState"] != null)
                e.LayoutData = (string)Session["myGridState"];
        }
        else
            Session["myGridState"] = e.LayoutData;
    };

然后在单击按钮时,您应该像这样保存网格状态:

<script type="text/javascript">
function SaveLayoutData() {
    $.getJSON("@Url.Action("SaveLayoutData", "MyController" })", null,
        function (result) {
            if(result == 'success') {
                alert("Layout save success");
            }
        });
}
</script>

在控制器中:

    public JsonResult SaveLayoutData()
    {
       _gridStateRepository.Save(Session["myGridState"]);
       return Json("success", JsonRequestBehavior.AllowGet);
    }

当您加载网格时,您应该从数据库中加载网格状态并将其写入 Session["myGridState"]

于 2012-05-11T12:33:19.720 回答