[CLOSED] ServerMapping with AjaxProxy in GridPanel

  1. #1

    [CLOSED] ServerMapping with AjaxProxy in GridPanel

    Hi,
    I have a problem when using ServerMapping with AjaxProxy in GridPanel
    Here is my test code:
    Views:
    @using System.Globalization
    @using Unify.Admin.Controllers
    @{
        Layout = null;
    }
    
    @Html.X().ResourceManager()
    @(Html.X().GridPanel().ForceFit(true)
    .Store(s => 
        s.Add(Html.X().Store()
                .Proxy(Html.X().AjaxProxy()
                                            .Url(Url.Action("GetEvents"))
                                            .Reader(Html.X().JsonReader().Root("data")))
            //.DataSource(MyEvent.GetEvents())
            .Model(Html.X().Model()
            
                        .Fields(f =>
                        {
                            
                            f.Add(Html.X().ModelField().Name("StudentName").Type(ModelFieldType.String).ServerMapping("Student.Name"));
                            f.Add(Html.X().ModelField().Name("StudentNo").Type(ModelFieldType.String).ServerMapping("Student.StudentNo"));
                            f.Add(Html.X().ModelField().Name("ID"));
                            f.Add(Html.X().ModelField().Name("Desc"));
                        }))
                        
                    )
    
    )
    .ColumnModel(c =>
        {
            c.Columns.Add(Html.X().Column().DataIndex("ID").Text("ID"));
            c.Columns.Add(Html.X().Column().DataIndex("Desc").Text("Desc"));
            c.Columns.Add(Html.X().Column().DataIndex("StudentName").Text("StudentName"));
            c.Columns.Add(Html.X().Column().DataIndex("StudentNo").Text("StudentNo"));
    
        }))
    Controllers:

    public StoreResult GetEvents()
            {
                List<MyEvent> events = MyEvent.GetEvents();
                return new StoreResult(events, events.Count);
            }
    Classes
        public class MyEventBase
        {
            public int ID { get; set; }
        }
    
        public class MyEvent : MyEventBase
        {
            public MyStudent Student { get; set; }
            public string Desc { get; set; }
            public static List<MyEvent> GetEvents()
            {
                return new List<MyEvent>
                    {
                        new MyEvent
                            {ID = 1, Desc = "EventDesc1", Student = null},
                        new MyEvent
                            {ID = 2, Desc = "EventDesc2", Student = new MyStudent {StudentNo = "0001", Name = "Student Name1 "}}
                    };
            }
        }
    
        public class MyStudent
        {
            public string StudentNo { get; set; }
            public string Name { get; set; }
        }
    It works fine when I use .DataSource(MyEvent.GetEvents()) in the Views.

    Another question is: When I use StoreFor<> Control in the Views, How can I add new Field in the Store Model with ServerMapping?

    Thanks in advance.
    Last edited by Daniil; Oct 26, 2012 at 5:54 PM. Reason: [CLOSED]
  2. #2
    ServerMapping cannot be used in conjuction with AjaxProxy because you serialize data manually on the server (store doesn't participate in serialization process)

Similar Threads

  1. AjaxProxy Example
    By yash.kapoor in forum 2.x Help
    Replies: 8
    Last Post: Dec 20, 2012, 9:39 AM
  2. [CLOSED] [Razor] AjaxProxy pass extra parameter
    By boris in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Sep 07, 2012, 8:15 AM
  3. Replies: 6
    Last Post: Jun 25, 2012, 3:50 PM
  4. Replies: 0
    Last Post: Jun 03, 2012, 3:46 AM
  5. [CLOSED] Set actionMethods of AJAXProxy
    By T3rryChan in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 23, 2012, 7:08 PM

Posting Permissions