[CLOSED] [2.0] Razor and Store LoadData

Hybrid View

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

    [CLOSED] [2.0] Razor and Store LoadData

    Hello,

    Just curious how one would load data into a store without a proxy; with razor.

    Any example? I've got a list of objects, would like to bind to the store.

    Cheers,
    Timothy
    Last edited by Daniil; Jun 28, 2012 at 9:05 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Just return a data from the controller and load them into the store client side.

    Example View
    <!DOCTYPE html>
    
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>    
    </head>
    <body>
        @Html.X().ResourceManager()
    
        @(Html.X().ComboBox()
            .QueryMode(DataLoadMode.Local)
            .Store(store =>
                store.Add(Html.X().Store()
                    .ID("Store1")
                    .Model(model =>
                        model.Add(Html.X().Model()
                            .Fields(fields =>
                            {
                                fields.Add(Html.X().ModelField().Name("text"));
                                fields.Add(Html.X().ModelField().Name("value"));
                            })
                        )
                    )
                )
            )
        )
    
        @(Html.X().Button()
            .Text("LoadData")
            .DirectEvents(de =>
                {
                    de.Click.Url = "/Razor/LoadData";
                    de.Click.Success = "App.Store1.loadData(result.result);";
                }
            )
        )
    </body>
    </html>
    Example Action
    public ActionResult LoadData()
    {
        object data = new object[]
        {
            new 
            {
                text = "Item 1",
                value = "1"
            },
            new 
            {
                text = "Item 2",
                value = "2"
            }
        };
    
        return new AjaxResult(data);
    }
  3. #3
    Another approach is using the X.GetCmp feature.

    Example View
    <!DOCTYPE html>
    
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>    
    </head>
    <body>
        @Html.X().ResourceManager()
    
        @(Html.X().ComboBox()
            .QueryMode(DataLoadMode.Local)
            .Store(store =>
                store.Add(Html.X().Store()
                    .ID("Store1")
                    .Model(model =>
                        model.Add(Html.X().Model()
                            .Fields(fields =>
                            {
                                fields.Add(Html.X().ModelField().Name("text"));
                                fields.Add(Html.X().ModelField().Name("value"));
                            })
                        )
                    )
                )
            )
        )
    
        @(Html.X().Button()
            .Text("LoadData")
            .DirectEvents(de =>
                {
                    de.Click.Url = "/Razor/LoadData";
                    de.Click.ExtraParams.Add(new Parameter("storeId", "Store1", ParameterMode.Value));
                }
            )
        )
    </body>
    </html>
    Example Action
    public ActionResult LoadData(string storeId)
    {
        Store store = X.GetCmp<Store>(storeId);
        object data = new object[]
        {
            new 
            {
                text = "Item 1",
                value = "1"
            },
            new 
            {
                text = "Item 2",
                value = "2"
            }
        };
        store.LoadData(data);
    
        return new AjaxResult();
    }
  4. #4
    Hello Daniil,

    Thanks for the suggestions. Is there a way to do it without having to call an action? Can you just call loadData on the store, from Razor, with a data object from the ViewData?

    Cheers,
    Timothy
  5. #5
    Quote Originally Posted by Timothy View Post
    Can you just call loadData on the store, from Razor, with a data object from the ViewData?
    On the fly via JavaScript? I don't think so. Or, though, you should render that object data to client.

    Or do you need that on initial load? If so, just apply that object for Store DataSource.
  6. #6
    Thanks Daniil, ugh I don't know why I didn't think of the DataSource property. I'll try working with that :)

    Cheers,
    Timothy
  7. #7
    Quote Originally Posted by Daniil View Post
    Or do you need that on initial load? If so, just apply that object for Store DataSource.
    "Data" instead of "DataSource".

    @Html.X().Store().Control(c => { c.Data= ViewData["data"]; })
    We will add the Data property in v2.1.

Similar Threads

  1. Store.loadData()
    By glenh in forum 1.x Help
    Replies: 2
    Last Post: Dec 05, 2011, 3:34 AM
  2. About Ext.Net Store.loadData
    By caoit in forum 1.x Help
    Replies: 0
    Last Post: Apr 26, 2011, 2:41 AM
  3. [1.0] Store.LoadData vs DataBind
    By Kam in forum 1.x Help
    Replies: 1
    Last Post: Apr 19, 2011, 11:00 AM
  4. [CLOSED] Store loadData() wierd error.
    By capecod in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Nov 10, 2010, 8:46 AM
  5. Ext.Net Store.loadData
    By cleve in forum 1.x Help
    Replies: 4
    Last Post: Jun 29, 2010, 4:19 PM

Tags for this Thread

Posting Permissions