[CLOSED] How to bind a store to a viewmodel

  1. #1

    [CLOSED] How to bind a store to a viewmodel



    Hi to all

    I have two questions:

    1) How it is possible to bind a store to a view model of a user control?

    
    
    
    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BPM.MVC.Web.ViewData.PlayerViewData>"%>
    
    
    <ext:ResourceManagerProxy ID="ResourceManagerProxy1" runat="server" />
    
    
    <ext:Store ID="Players" runat="server" AutoDataBind="true" AutoLoad="true" DataSource="<%# Model.PlayerList %>">
    
    
    <Reader>
    
    
    <ext:JsonReader IDProperty="ID">
    
    
    <Fields>
    
    
    <ext:RecordField Name="FirstName" />
    
    
    <ext:RecordField Name="LastName" />
    
    
    <ext:RecordField Name="ClubName" />
    
    
    <ext:RecordField Name="IndexNumber" />
    
    
    </Fields>
    
    
    </ext:JsonReader>
    
    
    </Reader>
    
    
    </ext:Store>
    
    
    <ext:GridPanel 
    
    
    ID="GridPanel1" 
    
    
    runat="server" 
    
    
    Title="Players" 
    
    
    Frame="true" 
    
    
    StoreID="Players" 
    
    
    Height="600">
    
    
    <ColumnModel ID="ColumnModel1" runat="server">
    
    
    <Columns>
    
    
    <ext:Column DataIndex="FirstName" Header="FirstName" Width="150" />
    
    
    <ext:Column DataIndex="LastName" Header="LastName" Width="150" />
    
    
    <ext:Column DataIndex="ClubName" Header="ClubName" Width="150" />
    
    
    <ext:Column DataIndex="IndexNumber" Header="IndexNumber" Width="150" />
    
    
    </Columns>
    
    
    </ColumnModel>
    
    
    <View>
    
    
    <ext:GridView ID="GridView1" runat="server" EnableRowBody="true">
    
    
    <GetRowClass Handler="rowParams.body = '<p>' + record.data.Notes + '</p>'; return 'x-grid3-row-expanded';" />
    
    
    </ext:GridView>
    
    
    </View>
    
    
    <SelectionModel>
    
    
    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
    
    
    </SelectionModel>
    
    
    </ext:GridPanel>
    2) How should I pass the ViewData using the controller as follows:

    
    
    
    
    public Ext.Net.MVC.PartialViewResult xIndex(string containerId)
    
    
    {
    
    
    PlayerViewData <U>viewData</U> = ViewDataFactory.CreateBaseViewData<PlayerViewData>("Player List");
    
    
    return new Ext.Net.MVC.PartialViewResult(containerId, RenderMode.RenderTo);
    
    
    }
    Thank you for help;-)

    Best regards,
    Tiramisu




  2. #2

    RE: [CLOSED] How to bind a store to a viewmodel

    Hi,

    Ext.Net.MVC.PartialViewResult is inherited from the ViewResultBase therefore it has ViewData property
  3. #3

    RE: [CLOSED] How to bind a store to a viewmodel

    Hi vladimir

    How can I bind the model to the store? I've tried different methods but nothing seams to work...

  4. #4

    RE: [CLOSED] How to bind a store to a viewmodel

    Hi,

    Please see the following sample
    View
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                Store1.DataSource = this.Model;
                Store1.DataBind();
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" InitScriptMode="Inline" />
        
        <ext:Store runat="server" ID="Store1">
            <Reader>
                <ext:JsonReader IDProperty="Id">
                    <Fields>
                        <ext:RecordField Name="Id" Type="Int" />
                        <ext:RecordField Name="Company" Type="String" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <SortInfo Field="Company" Direction="ASC" />
        </ext:Store>
        
        <ext:Window 
            ID="Window1" 
            runat="server" 
            Width="700" 
            Height="400" 
            Closable="false"
            Collapsible="true" 
            Title="Example"
            Maximizable="true"
            Layout="Fit">
            <Items>
                <ext:GridPanel 
                    runat="server" 
                    ID="GridPanel1" 
                    Border="false"
                    StoreID="Store1">
                    <ColumnModel runat="server">
                        <Columns>
                            <ext:Column Header="Id" DataIndex="Id" />
                            <ext:Column Header="Company" DataIndex="Company" />
                        </Columns>
                    </ColumnModel>
                    <LoadMask ShowMask="true" />
                </ext:GridPanel>
            </Items>
        </ext:Window>    
    </body>
    </html>
    Controller
    public class TestController : Controller
        {
            public ActionResult Index()
            {
    
                return View(new List<object> {
                    new {Id = 1, Company = "Company1"},
                    new {Id = 2, Company = "Company2"},
                    new {Id = 3, Company = "Company3"}
                });
            }
        }

    But I think it is better (and it is required if you need to implement remote paging) to use proxy
    View
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        
        <ext:Store runat="server" ID="Store1" >
            <Proxy>
                <ext:HttpProxy Url="/Test/GetCustomerList/" />
            </Proxy>
            <Reader>
                <ext:JsonReader IDProperty="Id" Root="data" TotalProperty="total">
                    <Fields>
                        <ext:RecordField Name="Id" Type="Int" />
                        <ext:RecordField Name="Company" Type="String" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <SortInfo Field="Company" Direction="ASC" />
        </ext:Store>
        
        <ext:Window 
            ID="Window1" 
            runat="server" 
            Width="700" 
            Height="400" 
            Closable="false"
            Collapsible="true" 
            Title="Example"
            Maximizable="true"
            Layout="Fit">
            <Items>
                <ext:GridPanel 
                    runat="server" 
                    ID="GridPanel1" 
                    Border="false"
                    StoreID="Store1">
                    <ColumnModel runat="server">
                        <Columns>
                            <ext:Column Header="Id" DataIndex="Id" />
                            <ext:Column Header="Company" DataIndex="Company" />
                        </Columns>
                    </ColumnModel>
                    <LoadMask ShowMask="true" />
                </ext:GridPanel>
            </Items>
        </ext:Window>    
    </body>
    </html>
    Controller
    public class TestController : Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
            public AjaxStoreResult GetCustomerList(string dir, string sort)
            {
                return new AjaxStoreResult(new List<object> {
                    new {Id = 1, Company = "Company1"},
                    new {Id = 2, Company = "Company2"},
                    new {Id = 3, Company = "Company3"}
                }, 3);
            }
        }

Similar Threads

  1. Replies: 0
    Last Post: Jun 19, 2012, 7:59 AM
  2. How to Bind Panel with Store?
    By webppl in forum 1.x Help
    Replies: 2
    Last Post: Oct 07, 2010, 2:46 AM
  3. MVC with ViewModel pattern (MVVM)
    By Dominik in forum 1.x Help
    Replies: 1
    Last Post: May 28, 2010, 7:08 AM
  4. [CLOSED] Bind XElement to EXT Store
    By sharif in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 24, 2010, 9:52 AM
  5. About Store Bind?
    By GeoffreyRen in forum 1.x Help
    Replies: 2
    Last Post: Jul 07, 2009, 10:22 PM

Posting Permissions