Ext.Net MVC从控制器刷新Panelgrid

时间:2013-06-06 22:57:59

标签: asp.net-mvc ext.net

在我看来有这个:

@{
 var properties = db.StylesPropertyDefs.OrderBy(o => o.PropertyId);
}

..
..
@(Html.X().GridPanel()
      .Title("Array Grid")
      .ID("propertyGrid")
      .Width(600)
      .Height(350)
      .Store(Html.X().Store()
                 .Model(Html.X().Model()
                            .Fields(
                                new ModelField("PropertyId", ModelFieldType.Int),
                                new ModelField("PropertyName", ModelFieldType.String),
                                new ModelField("PropertyShortName", ModelFieldType.String),
                                new ModelField("PropertyActiveFlag", ModelFieldType.Boolean)
                            )
                 ).DataSource(properties)
..
..

我在控制器中有一个动作来添加新属性。新属性添加成功但我可以刷新PanelGrid(不刷新整个页面)。这是控制器:

    [DirectMethod]
    public ActionResult AddNewProperty(string propertyName, string propertyCode, bool propertyActive)
                {
                    if (propertyName == "" || propertyCode=="")
                    {
                        X.Msg.Show(new MessageBoxConfig
                        {
                            Title = "Error",
                            Message = "The field name or code can not be empty.",
                            Buttons = MessageBox.Button.OK,
                            Icon = MessageBox.Icon.ERROR
                        });
                        return this.Direct();
                    }

    //if all is ok add new property
                    var newOne = new StylesPropertyDef
                        {
                            PropertyActiveFlag = propertyActive,
                            PropertyName = propertyName,
                            PropertyShortName = propertyCode
                        };
                    var db = new TaosKnowledgeDataContext(DataUtils.GetConStringLocal());
                    db.StylesPropertyDefs.InsertOnSubmit(newOne);
                    db.SubmitChanges();

    //reload properties
                    var properties = db.StylesPropertyDefs.OrderBy(o => o.PropertyId);

                    var theGrid = X.GetCmp<GridPanel>("propertyGrid");
//now i need refresh or reload the panel grid.


                    X.GetCmp<Window>("AddNewProperty").Close();
                    return this.Direct();
                    //return RedirectToAction("StyleProperties");
                }

所以,恢复,我需要从控制器刷新PanelGrid数据源(或存储)。 请你能帮帮我吗?

2 个答案:

答案 0 :(得分:0)

请尝试以下操作。

  1. 为商店设置ID。

    .ID("Store1")
    
  2. 在控制器操作中执行以下操作。

    Store store = X.GetCmp<Store>("Store1");
    store.DataSource = db.StylesPropertyDefs.OrderBy(o => o.PropertyId);
    store.DataBind();
    

答案 1 :(得分:0)

确定。我解决了 我删除了Store中的Datasource,并将代理阅读器放到Controller中。

.Proxy(
       Html.X().AjaxProxy()
       .Url(Url.Action("Read"))
       .Reader(Html.X().JsonReader().Root("data"))
      )

在控制器中:

public ActionResult Read()
        {
            var db = new TaosKnowledgeDataContext(DataUtils.GetConStringLocal());
            var properties = db.StylesPropertyDefs.OrderBy(o => o.PropertyId);
            return this.Store(properties);
        }

插入新属性时:

var store = X.GetCmp<Store>("Store1");
store.Reload();

非常感谢。