[CLOSED] AjaxResult and AjaxStoreResult

  1. #1

    [CLOSED] AjaxResult and AjaxStoreResult

    In our MVC application, I'm trying to return XML from a controller using either AjaxReturn or AjaxStoreReturn. However, the ext:Store can't seem to process the returned xml. I've changed the Reader type of the ext:Store to JsonReader and XmlReader with the same result. Do I need to convert the xml to something before sending it back to the store?

    Note that the xml is generated dynamically and is formatted like the plant.xml sample with the transformation plant.xsl.
  2. #2

    RE: [CLOSED] AjaxResult and AjaxStoreResult

    Hi,

    Do you return pure xml response or xml string inside JSON object? Does response has type "text/xml"? What xml content and how you configured the XmlReader?

    Please demonstrate an example
    Vladimir Shcheglov
    Sr. Developer
  3. #3

    RE: [CLOSED] AjaxResult and AjaxStoreResult

    I've tried to return using both AjaxResult and AjaxStoreResult the XmlDocument and also InnerXml (string). But the JsonReader and also XmlReader in the Store can't seem to process the return.
    Below is exactly what is being passed back as pure xml. I believe the xml format is the same format as the example you guys have on the GridPanel XMLDataSource plant.xsl which then a JsonReader is able to process:
    <permissions>
        <permission folder="Sales" report="SalesReport1" role1="true" role2="true" role3="false">
        </permission>
    </permissions>
    I tried this JsonReader:
        <ext:Store runat="server" ID="Store1" GroupField="folder">
            <Proxy>
                <ext:HttpProxy Url="/Administration/GetPermissions/" />
            </Proxy>
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="folder" />
                        <ext:RecordField Name="report" />
                        <ext:RecordField Name="role1" Type="Boolean" />
                        <ext:RecordField Name="role2" Type="Boolean" />
                        <ext:RecordField Name="role3" Type="Boolean" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <SortInfo Field="folder" Direction="ASC" />
        </ext:Store>
    I tried this XmlReader:
        <ext:Store runat="server" ID="Store1" GroupField="folder">
            <Proxy>
                <ext:HttpProxy Url="/Administration/GetPermissions/" />
            </Proxy>
            <Reader>
                <ext:XmlReader Record="permission">
                    <Fields>
                        <ext:RecordField Name="folder" />
                        <ext:RecordField Name="report" />
                        <ext:RecordField Name="role1" Type="Boolean" />
                        <ext:RecordField Name="role2" Type="Boolean" />
                        <ext:RecordField Name="role3" Type="Boolean" />
                    </Fields>
                </ext:XmlReader>
            </Reader>
            <SortInfo Field="folder" Direction="ASC" />
        </ext:Store>
    Thanks for the support!
  4. #4

    RE: [CLOSED] AjaxResult and AjaxStoreResult

    Hi,

    I am afraid that it is impossible what you try to accomplish with current implementation

    AjaxResult and AjaxStoreResult always return JSON object therefore the XML will be accessable as field of JsonReader. You can get whole XML as string but you need parse XML manually (store will not parse that XML because it is part of JSON object). Even if you able parse that XML you have to create records and add it to the store. It is lot of code in javascript. Therefore I recomend to return simple server side collection (for example, List<MyType>)

    You can easly convert XML to required collection. For example, see how we convert XML to the required collection in the demo application Ext.Net.MVC

    public AjaxStoreResult GetHomeSchema()
            {
                XElement document = XElement.Load(Server.MapPath("~/resources/images/HomeSchema.xml"));
                var defaultIcon = &#100;ocument.Attribute("defaultIcon") != null ? &#100;ocument.Attribute("defaultIcon").Value : "";
                var query = from g in &#100;ocument.Elements("group")
                            select new
                                       {
                                           Title = g.Attribute("title") != null ? g.Attribute("title").Value : "",
                                           Items = (from i in g.Elements("item") 
                                                    select new
                                                               {
                                                                   Title = i.Element("title") != null ? i.Element("title").Value : "",
                                                                   Icon = i.Element("item-icon") != null ? i.Element("item-icon").Value : defaultIcon,
                                                                   Accordion = i.Element("accordion-item") != null ? i.Element("accordion-item").Value : "",
                                                                   MenuItem = i.Element("menu-item") != null ? i.Element("menu-item").Value : ""
                                                               }
                                                    )
                                       };
    
                return new AjaxStoreResult(query);
            }
    Store
    <ext:Store runat="server" ID="Store1" AutoLoad="true">
            <Proxy>
                <ext:HttpProxy Url="/Data/GetHomeSchema/" />
            </Proxy>
            <Reader>
                <ext:JsonReader Root="data">
                    <Fields>
                        <ext:RecordField Name="Title" />
                        <ext:RecordField Name="Items" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>

    P.S. XmlReader can be using if you return pure XML response with type "text/xml" (like classic WebService response)
    Vladimir Shcheglov
    Sr. Developer
  5. #5

    RE: [CLOSED] AjaxResult and AjaxStoreResult

    Vladimir ,
    Your suggestion of using LINQ to XML in returning data to ext:Store worked great (should have thought of that)! I changed the XML to be elements based instead of attributes to work better. However, due to the dynamic elements in the XML (roles is dynamic), I can't hard code the columns in the select statement:
    // this works with the ext:Store
    XElement xeTemp = XElement.Parse(xmldoc.InnerXml);
    var query = from g in xeTemp.Elements("permission");
                    select new
                    {
                        folder = g.Element("folder").Value,
                        report = g.Element("report").Value,
                        role1 = g.Element(role1").Value,
                        role2 = g.Element(role2").Value,
                        role3 = g.Element(role3").Value,
                    }
    return new AjaxStoreResult(query);
    // this DOES NOT work with the ext:Store. i get an empty row in the gridpanel
    XElement xeTemp = XElement.Parse(xmldoc.InnerXml);
    var query = from g in xeTemp.Elements("permission");
                    select g;
    return new AjaxStoreResult(query);
    Also is the Ext.Net.MVC application demo you refer to the same as the http://mvc.ext.net?

    Thanks again for the support!
  6. #6

    RE: [CLOSED] AjaxResult and AjaxStoreResult

    Hi,

    Do you still need our assistance or we can mark this topic as solved?


    P.S. Yes, Ext.Net.MVC is mvc.ext.net. Just converted to using the Ext.Net 1.0
    Vladimir Shcheglov
    Sr. Developer
  7. #7

    RE: [CLOSED] AjaxResult and AjaxStoreResult

    Since hardcoding is never a good idea, I would still need help in returning the query back to the ext:Store without hardcoding the columns. I've been searching the net all over on this. Any ideas?

Similar Threads

  1. [CLOSED] Update v2.0 combobox with AjaxResult
    By romeu in forum 2.x Premium Help
    Replies: 18
    Last Post: May 10, 2012, 9:31 PM
  2. [CLOSED] [1.0] MVC AjaxResult
    By alliedwallet.com in forum 1.x Premium Help
    Replies: 2
    Last Post: Jan 21, 2011, 9:07 AM
  3. [CLOSED] AjaxStoreResult and ExtraParams
    By Stefanaccio in forum 1.x Premium Help
    Replies: 5
    Last Post: Oct 28, 2010, 6:24 PM
  4. AjaxResult class issue in ext.net.dll
    By vs.mukesh in forum 1.x Help
    Replies: 4
    Last Post: Jun 10, 2010, 2:38 PM
  5. [CLOSED] [1.0] MVC AjaxStoreResult Question
    By Timothy in forum 1.x Premium Help
    Replies: 3
    Last Post: Feb 26, 2010, 11:14 AM

Posting Permissions