[OPEN] [#183] Data annotations appear to break store batch update mechanisms

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [OPEN] [#183] Data annotations appear to break store batch update mechanisms

    I am attempting to dynamically add records to a store and then synchronize the store with an ASP.NET MVC 4 server. I can add records to the store; however, the store will not acknowledge the records in the getChangedDatamethod or an invocation of the sync method. It appears to detect deleted or changed records. I have isolated the problem and noted it occurs when you include a StringLength data annotation attribute on a string property in the model.

    Environment
    • Visual Studio 2012
    • ASP.NET MVC 4
    • Ext.NET SVN r4964


    Steps to Reproduce
    1. Execute the provided sample
    2. Modify a record in the grid panel or add a record with the add button
    3. Press the save button
    4. Observe the console


    Comments

    If you look at the client-side javascript, the data annotation adds validation information to the store's model (this is expected); however, this appears to prevent the store from properly reporting created or changed records. The side effect is methods such as sync and getChangedData do not work properly.

    If you remove the StringLength data annotation, the store will properly report created or changed records again.

    Model
        [Model(Name = "TestModel", ClientIdProperty = "PhantomId")]
        public class TestModel
        {
    
            [ModelField(IDProperty = true, UseNull = true)]
            public int ID { get; set; }
    
            [ModelField(Ignore = true)]
            public string PhantomId { get; set; }
    
            [StringLength(32)]
            public string Name { get; set; }
    
            public TestModel(string name)
            {
                this.Name = name ?? String.Empty;
            }
    
        }
    View
      @(Html.X().GridPanel()
            .ID("TestGrid")
            .TopBar(Html.X().Toolbar()
                .Items(
                    
                    Html.X().Button()
                        .Text("Add")
                        .OnClientClick("Test.onAdd()"),
                        
                Html.X().Button()
                    .Text("Save")
                    .OnClientClick("Test.onSave()")
                    
                )
            )
            .Store(Html.X().StoreFor(typeof(TestModel))
                .Proxy(Html.X().AjaxProxy()
                    .Url(Url.Action("Retrieve"))
                    .ActionMethods(m => m.Read = HttpMethod.POST)
                    .Reader(Html.X().JsonReader()
                        .Root("Data")
                    )
                )
            )
            .ColumnModel(
                Html.X().Column().Text("Name").DataIndex("Name")
                    .Editor(Html.X().TextField())
            )
            .Plugins(Html.X().CellEditing())
        )
    Script
    var Test = {
    
        onAdd: function() {
    
            var grid = Ext.getCmp('TestGrid');
            var store = grid.store;
    
            var record = store.model.create();
            
            store.add(record);
    
        },
    
        onSave: function () {
            
            var grid = Ext.getCmp('TestGrid');
            var store = grid.store;
    
            var data = store.getChangedData(
                    { skipIdForPhantomRecords: false });
    
            console.log(data);
    
        }
    
    };
    Controller
        public class TestController : Controller
        {
            public static List<TestModel> Models = new List<TestModel>();
    
            static TestController() {
                for (int i = 0; i < 5; i++)
                    Models.Add(new TestModel(String.Format("Record {0}", i + 1)));
            }
    
            public ActionResult Index()
            {
                return View();
            }
    
            [HttpPost]
            public ActionResult Retrieve()
            {
                return this.Json(Models);
            }
    
        }
    Last edited by Daniil; Apr 02, 2013 at 2:15 PM. Reason: [OPEN] [#183]

Similar Threads

  1. [CLOSED] GridPanel Batch Update does not send data
    By chrish in forum 2.x Legacy Premium Help
    Replies: 11
    Last Post: Feb 18, 2013, 3:38 AM
  2. Replies: 1
    Last Post: Feb 17, 2013, 3:49 PM
  3. Batch Update
    By shaileshsakaria in forum 2.x Help
    Replies: 1
    Last Post: Jan 18, 2013, 4:17 PM
  4. [CLOSED] MVC3 Data Annotations/Validation
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 11
    Last Post: Aug 26, 2012, 8:06 AM
  5. Replies: 0
    Last Post: Apr 12, 2011, 3:32 PM

Tags for this Thread

Posting Permissions