保存网格布局数据

时间:2012-05-08 11:47:15

标签: asp.net-mvc-3 devexpress

我在网格设置中有这个:

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

我想有一个用于在数据库中保存gridstate的按钮和一个用于重置它的按钮。你能救我吗?

1 个答案:

答案 0 :(得分: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”]