[3.2.1] Ext.Net.Mvc Store. Various interpretations enum values

  1. #1

    [3.2.1] Ext.Net.Mvc Store. Various interpretations enum values

    Hello,

    StoreFor creates model when enum property is interpreted as number but in StoreResult and Store.Data returns enum values as strings.
    Please, unify this.

    View:
    @using Ext.Net;
    @using Ext.Net.MVC;
    
    @model IEnumerable<ExtNetTest.Test.Models.EnumTestModel>
    
    @{
        Layout = null;
        
        var X = Html.X();
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <title>Test</title>
    </head>
    <body>
        @(Html.X().ResourceManager().Theme(Theme.Neptune))
    
        @(X.GridPanel()
            .Title("Using StoreFor(m => m)")
            .Width(300)
            .Height(200)
            .Store(X.StoreFor(m => m))
            .ColumnModel(
                X.Column().DataIndex("EnumValue").Text("Enum Value")
            )
        )
    
        @(X.GridPanel()
            .Title("Using StoreFor<EnumTestModel>(true) and Data property")
            .Width(300)
            .Height(200)
            .Store(X.StoreFor<ExtNetTest.Test.Models.EnumTestModel>(true)
                .Data(Model)
            )
            .ColumnModel(
                X.Column().DataIndex("EnumValue").Text("Enum Value")
            )
        )
    
        @(X.GridPanel()
            .Title("Using StoreFor<EnumTestModel>(true) and Proxy")
            .Width(300)
            .Height(200)
            .Store(X.StoreFor<ExtNetTest.Test.Models.EnumTestModel>(true)
                .Proxy(
                    X.AjaxProxy()
                        .Url(@Url.Action("GetDataAction"))
                        .Reader(X.JsonReader().RootProperty("data"))
                )
            )
            .ColumnModel(
                X.Column().DataIndex("EnumValue").Text("Enum Value")
            )
        )
    
        @(X.GridPanel()
            .Title("Using StoreFor(m => m) and Proxy.")
            .Width(300)
            .Height(200)
            .TopBar(X.Toolbar()
                .Items(
                    X.Label().Text("Click Refresh button to reload data -> "),
                    X.Button()
                        .Text("Refresh")
                        .Handler("this.up('grid').getStore().load();")
                )
            )
            .Store(X.StoreFor(m => m)
                .AutoLoad(false)
                .Proxy(
                    X.AjaxProxy()
                        .Url(@Url.Action("GetDataAction"))
                        .Reader(X.JsonReader().RootProperty("data"))
                )
            )
            .ColumnModel(
                X.Column().DataIndex("EnumValue").Text("Enum Value")
            )
        )
    </body>
    </html>
    Controller:
    using System.Web.Mvc;
    using Ext.Net;
    using Ext.Net.MVC;
    using ExtNetTest.Test.Models;
    using System.Collections.Generic;
    
    namespace ExtNet.Test.Controllers
    {
        public class ExtNetController : Controller
        {
            private IList<EnumTestModel> GetData()
            {
                return new List<EnumTestModel>()
                {
                    new EnumTestModel { EnumValue = TestEnum.EnumValue1 },
                    new EnumTestModel { EnumValue = TestEnum.EnumValue2 }
                };
            }
    
            public ActionResult Index()
            {
                return this.View(GetData());
            }
    
            public ActionResult GetDataAction()
            {
                return this.Store(GetData());
            }
        }
    }
    Model
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;
    namespace ExtNetTest.Test.Models
    {
        public enum TestEnum
        { 
            EnumValue1,
            EnumValue2
        }
    
        public class EnumTestModel
        {
            public TestEnum EnumValue { get; set; }
        }
    }
  2. #2
    Hi Yury,

    Thank you for pointing it out and especially for a clear test case.

    I agree it would be good to get same results using different data binding approaches. Unfortunately, it didn't happen when all this functionality has been implemented and changing it now would be a breaking change which, personally, I am reluctant to introduce.
  3. #3
    Hi, Daniil.

    Can you suggest how to use StoreFor(m => m) in view and StoreResult in action method together with identical enumeration type?
    Can you add something like Type property to ModelFieldAttribute or ModelAttribute, or add Newtonsoft data converters to StoreResult (this.Store) as a parameter?
  4. #4
    Sorry for the delay in answering.

    A possible solution could be:
    public ActionResult GetDataAction()
    {
        Store store = new Store();
        store.InitByType(typeof(EnumTestModel), true, true);
        Model model = store.Model[0];
    
        return this.Store(GetData(), model);
    }
    It creates a Store in a way that .StoreFor(m => m) does it. Then it passes its Model to deserialize the data according to that Model.

Similar Threads

  1. [FIXED] Bug on Enum conversion
    By JCKodel in forum Bugs
    Replies: 1
    Last Post: Nov 27, 2012, 8:04 AM
  2. [CLOSED] Store and enum bindings
    By digitek in forum 1.x Premium Help
    Replies: 5
    Last Post: Aug 01, 2012, 10:44 AM
  3. [CLOSED] Fill a store with an enum
    By 78fede78 in forum 1.x Premium Help
    Replies: 5
    Last Post: Nov 10, 2010, 5:50 PM
  4. Enum in Store
    By EzaBlade in forum 1.x Help
    Replies: 0
    Last Post: Jul 07, 2009, 8:03 PM
  5. Coolite 0.7 + Enum support in Store
    By echo in forum Open Discussions
    Replies: 1
    Last Post: Dec 16, 2008, 6:10 AM

Posting Permissions