[CLOSED] MVC, Binding model to Store

  1. #1

    [CLOSED] MVC, Binding model to Store

    Hi Guys,

    I am trying to bind my model directly to the Datasource property of a store. Is this possible, please advise. See my code below.



    <%@ Page Title="" Language="C#"  Inherits="System.Web.Mvc.ViewPage<List<MonitorMockups.Controllers.Langauge>>" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Monitor</title>    
        <style type="text/css">
            h1 {
                font: normal 60px tahoma, arial, verdana;
                color: #E1E1E1;
            }
            
            h2 {
                font: normal 20px tahoma, arial, verdana;
                color: #E1E1E1;
            }
            
            h2 a {
                text-decoration: none;
                color: #E1E1E1;
            }
            
            .x-window-mc {
                border-radius: 5px;
               -moz-border-radius: 5px;
            }
        </style>
        <script src="/Scripts/Validator.js" type="text/javascript"></script>
        <script src="/scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            if (window.top.frames.length !== 0) {
                window.top.location = self.document.location;
            }
        </script>
    </head>
    <body>
    
        <ext:ResourceManager ID="ResourceManager1" runat="server" CleanResourceUrl="false" />
             
          <ext:Window 
            ID="windowLogin"
            runat="server" 
            Closable="false"
            Resizable="false"
            Height="400" 
            Icon="Lock" 
            Title= "Languages"
            Draggable="true"
            Width="700"
            Modal="true"
            Layout="fit"
            BodyBorder="false"
            LabelAlign="Top"
            Padding="5"
            DefaultButton= "btnLogin"
            >        
            <Items>
                    <ext:FormPanel ID="fpLogin" 
                        runat="server" 
                        FormID="formLogin"
                        Border="false"
                        Layout="form"
                        BodyBorder="false" 
                        BodyStyle="background:transparent;" 
                        LabelAlign ="Top"
                        >
                        <Items>
                        <ext:ListView 
                        ID="ListView1" 
                        runat="server"
                        MultiSelect="true"
                        ReserveScrollOffset="true"
                        EmptyText="No Images to Display">
                        <Store>
                            <ext:Store ID="StoreListview" runat="server" AutoLoad="true" DataSource= '<%# Model.ToArray() %>' AutoDataBind="true">
                                <Reader>
                                    <ext:JsonReader IDProperty="Language" AutoDataBind="true">
                                        <Fields>
                                            <ext:RecordField Name="Language" AutoDataBind="true" />
                                            <ext:RecordField Name="LanguageId" AutoDataBind= "true" />      
                                            <ext:RecordField Name="Url" AutoDataBind="true" />
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                            </ext:Store>
                        </Store>
                        <Columns>
                            <ext:ListViewColumn 
                                Header="Language" 
                                Width="0.35" 
                                DataIndex="name" 
                                AutoDataBind="true" />
                            <ext:ListViewColumn 
                                Header="Language Id" 
                                Width="0.3" 
                                DataIndex="LanguageId" 
                                AutoDataBind="true" />
                            <ext:ListViewColumn 
                                Header="Status" 
                                Width="0.15" 
                                DataIndex="url" 
                                Template='<img style="width:60px;height:45px;" src="{url}" />' 
                                AutoDataBind="true" />
                        </Columns>
                        <Listeners>
                           
                        </Listeners> 
                    </ext:ListView>
                        </Items>
                    </ext:FormPanel>
            </Items>
            <Buttons> 
                <ext:Button 
                ID="btnLogin" 
                runat="server"
                TabIndex = "4"
                Text="OK"
                Icon="Accept">
                    <DirectEvents>
                        <Click 
                            AutoDataBind ="true"
                            Timeout="60000"
                            FormID="formLogin"
                            CleanRequest="true" 
                            Method="POST"
                            Failure="Ext.Msg.show({
                               title:   result.errorMessage.split(':')[0],
                               msg:     result.errorMessage.split(':')[1],
                               buttons: Ext.Msg.OK,
                               icon:    Ext.MessageBox.Warning
                            });"
                            >
                            <ExtraParams>
                                <ext:Parameter Name="ReturnUrl" Value="Ext.urlDecode(String(document.location).split('?')[1]).r || '/'" Mode="Raw" />
                            </ExtraParams>
                        </Click>
                    </DirectEvents>
                </ext:Button>
            </Buttons>
             <KeyMap>
                <ext:KeyBinding AutoDataBind="true" StopEvent="true">
                    <Keys>
                        <ext:Key Code="ENTER" />
                    </Keys>
                    <Listeners>
                        <Event Handler="if(Password.hasFocus || btnLogin.el.hasClass('x-btn-focus')){btnLogin.fireEvent('click')};" />
                    </Listeners>
                </ext:KeyBinding>
            </KeyMap>
    
        </ext:Window>
    
    </body>
    </html>
     public class LanguagesController : Controller
        {
            //
            // GET: /Languages/
    
            public ActionResult Index()
            {
                List<Langauge> data = new List<Langauge>();
    
                data.Add(new Langauge()
                {
                    Language = "English",
                    LanguageId = "en",
                    Url = "../../Images/Success.png",
                });
    
    
                data.Add(new Langauge()
                {
                    Language = "Spanish",
                    LanguageId = "es",
                    Url = "../../Images/Warning.png",
                });
    
                data.Add(new Langauge()
                {
                    Language = "French",
                    LanguageId = "es",
                    Url = "../../Images/Error.png",
                });
    
    
    
                return View(data);
            }
    
        }
    
        public class Langauge
        {
            public String Language { get; set; }
            public String LanguageId { get; set; }
            public String Url { get; set; }
        }
    Last edited by Daniil; Apr 15, 2011 at 12:05 PM. Reason: [CLOSED]
  2. #2
    Try this solution: into view add

    <script runat="server">
        protected void Page_Load(object sender, EventArgs args)
        {
            StoreListview.DataSource = Model.ToArray();
            StoreListview.DataBind();
        }
    </script>
  3. #3
    Hi,

    Yes, binding data from code behind sounds good.

Similar Threads

  1. [CLOSED] binding checkbox selection model
    By CarpFisher in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 18, 2012, 7:52 AM
  2. [CLOSED] Model Binding POSTed combobox values
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Mar 09, 2012, 1:36 PM
  3. binding checkbox selection model
    By VipulTyagi in forum 1.x Help
    Replies: 2
    Last Post: Apr 07, 2011, 11:36 AM
  4. [CLOSED] LoadControl and Store binding
    By Timur.Akhmerov in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 30, 2010, 2:50 PM
  5. [CLOSED] Store is not binding
    By majestic in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 01, 2010, 12:47 PM

Posting Permissions