[CLOSED] [#636] Difference between DirectMethod request params and Ajax request params

Page 2 of 3 FirstFirst 123 LastLast
  1. #11
    I am eager to hear your feedback. Hopefully, positive:)

    Anup, I just discovered that I didn't commit something in the revision #6249.

    Please update to the revision #6251, at least. It contains all the required changes.
  2. #12
    What incredibly amazing timing. I was just about to respond that I think there is a problem with the commit, because the debug version vs the individual file vs the full version seem very subtly different, and perhaps a commit was missing, because I was getting strange errors causing post backs and I narrowed it down to that change.

    Just as I was writing this up, I got your email notification about your previous post, so I got the revision after (with the tab fix) and compared the ext js files committed and saw it had the fixes/missed commits I think were needed.

    With that, I *think* this is working now.

    I need a fresh look tomorrow to confirm, but I think this is good so far.

    I tried to see what would happen if I made that encode false as a global settings, and I hit upon some errors, so I only set encode to false in the scenario I needed this and all is good.

    However, tomorrow (or Monday) I will try to run this in a bit more detail as I am wondering if the arguments is an even more complex object than our test case, and needed with the array, then encode false might result in too drastic a change. But I need to investigate further and create a more detailed test case to see...

    Thanks for the effort so far.
  3. #13
    Thank you for the feedback!

    I tried to see what would happen if I made that encode false as a global settings, and I hit upon some errors, so I only set encode to false in the scenario I needed this and all is good.
    Yes, it might be not OK to set it globally.

    However, tomorrow (or Monday) I will try to run this in a bit more detail as I am wondering if the arguments is an even more complex object than our test case, and needed with the array, then encode false might result in too drastic a change. But I need to investigate further and create a more detailed test case to see...
    That is really appreciated! If any issues appear, we will try to correct.
  4. #14
    Thanks Daniil.

    Although I still need to look at this, I thought I'd just mention something before I forget:

    Perhaps also update the documentation, like you have in the Examples Explorer for DirectMethods Overview
    http://examples.ext.net/#/Events/Dir...hods/Overview/

    Also, in that documentation, I noticed that the link to Ext.data.Connection.request documentation is to 4.1 of Ext JS, not 5.x.

    And, a minor clarification: the text says "This options object may contain any of the following properties, or options as defined in Ext.data.Connection.request" - where you say, "or", it implies it is one or the other. But I think these can be any combination of the ones you list plus the ones listed in the Ext JS docs?

    Finally, I think I notice cleanRequest is not mentioned in the documentation (I actually forget what it is for, even though I have been using it for years!)
  5. #15
    Thank you, Anup!

    Corrected Ext.data.Connection online and in my local Ext.NET sources (will be committing soon).

    Added a couple of words about a new Encode option (will be committing soon as well).

    As for a cleanRequest option. It is what written in your book for a DirectEvent's options;)
    This can be used when calling a different URL (see later) to submit the
    parameters related to this event only and not any other form controls.
    In others words it means that it doesn't submit a runat form.

    So, this option is not actual for an MVC application as no a runat form there.

    Also I would say that an option is not quite actual for DirectMethods as well, because, in my opinion, DirectMethods are not quite supposed to submit a form.

    It looks like a CleanRequest option is only actual for a DirectEvent in a Web Forms project. Do you agree?
  6. #16
    Thanks! Funny that it is in the book! I looked in the index and didn't see it mentioned so looked in the DirectMethod section and while there was a code example or two, it wasn't explained. I thought I just overlooked it. Forgot it is in the table of DirectEvents a bit earlier :) I guess that chapter was written almost 2.5 years ago now...

    But yeah, good point. It looks like it would not be needed in many cases, so I will try to remove where I can and see how it goes.

    Thanks!
  7. #17
    Hi,

    I think you can mark this as closed and resolved. I think it works.

    I expanded my test case to cover two more scenarios:
    1) A nested object in the parameters
    2) More parameters, which on the controller side are parsed as a second argument

    The nested object parameters did not work in any scenario (including Ext JS Ajax Request) and I think that is fine - in those scenarios probably setting the request type to be json data would be better, anyway.

    In the case of second controller arguments, it all worked.

    Sample test page:

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>DirectMethod with Arrays</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
            
        <ext:Button ID="Button3" runat="server" Text="Call controller with Direct and Ext JS Ajax request methods">
            <Listeners>
                <Click Handler="
                    var msgs = [];
                    
                    function getTestParams() {
                        return {
                            intProperty : 4,
                            stringProperty : 'blah',
                            arrayProperty : [116, 117],
                            nestedQuery: {
                                intProperty : 4,
                                stringProperty : 'blah',
                                arrayProperty : [116, 117]
                            },
                            anotherIntProperty : 24,
                            anotherStringProperty : '2blah',
                            anotherArrayProperty : [2116, 2117]
                        };
                    }
    
                    Ext.net.DirectMethod.request({
                        url: '/ArraysInDirectMethod/Query',
                        cleanRequest: true,
                        params: getTestParams(),
                        success: function(result) {
                            console.log('DirectMethod encode default ', result);
                        }
                    });
    
                    Ext.net.DirectMethod.request({
                        url: '/ArraysInDirectMethod/Query',
                        cleanRequest: true,
                        encode: false,
                        params: getTestParams(),
                        success: function(result) {
                            console.log('DirectMethod encode false: ', result);
                        }
                    });
    
                    Ext.Ajax.request({
                        url: '/ArraysInDirectMethod/Query',
                        method: 'POST',
                        params: getTestParams(),
                        success: function(response) {
                            console.log('Ext Ajax', JSON.parse(response.responseText).result);
                        }
                    });
                " />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    Controller

    namespace Ext.Net3.Tests.Controllers
    {
        public class Query
        {
            [JsonProperty(PropertyName = "intProperty")]
            public int IntProperty { get; set; }
    
            [JsonProperty(PropertyName = "stringProperty")]
            public string StringProperty { get; set; }
    
            [JsonProperty(PropertyName = "arrayProperty", NullValueHandling = NullValueHandling.Ignore)]
            public List<int> ArrayProperty { get; set; }
    
            [JsonProperty(PropertyName = "nestedQuery", NullValueHandling = NullValueHandling.Ignore)]
            public Query NestedQuery { get; set; }
        }
    
        public class AnotherQuery
        {
            [JsonProperty(PropertyName = "anotherIntProperty")]
            public int AnotherIntProperty { get; set; }
    
            [JsonProperty(PropertyName = "anotherStringProperty")]
            public string AnotherStringProperty { get; set; }
    
            [JsonProperty(PropertyName = "anotherArrayProperty", NullValueHandling = NullValueHandling.Ignore)]
            public List<int> AnotherArrayProperty { get; set; }
        }
    
        public class QueryResult
        {
            [JsonProperty(PropertyName = "query", NullValueHandling = NullValueHandling.Ignore)]
            public Query Query { get; set; }
    
            [JsonProperty(PropertyName = "anotherQuery", NullValueHandling = NullValueHandling.Ignore)]
            public AnotherQuery AnotherQuery { get; set; }
        }
    
        public class ArraysInDirectMethodController : Controller
        {
            [HttpPost]
            public ActionResult Query(Query query, AnotherQuery anotherQuery)
            {
                return this.Direct(new QueryResult { Query = query, AnotherQuery = anotherQuery });
            }
        }
    }
    For the moment, my scenarios seem to work (the nested object scenario was just something I thought about while doing this and was curious to see what would happen - it gets posted if you see the HTTP post request, but Ext.Object.toQueryString method probably doesn't cater/support nested objects, which I think is okay as when it gets this complex, it may be better to post as JSON.)

    If I come across any other issues I will raise a new request?

    Many thanks for resolving this so quickly!
  8. #18
    Thanks for the feedback!

    Re: nested objects

    Please try to add the attached files on the page (replace .txt with .js) and test such a DirectMethod with nested objects:
    Ext.net.DirectMethod.request({
       ...,
       encode: false,
       recursive: true
    });
    That recursive setting will to a .toQueryString() as the second parameter.
    http://docs.sencha.com/extjs/5.1/5.1...-toQueryString

    So, all the nested objects should go with a request, but I am not sure/do know if ASP.NET MVC can deal with that and it will be deserialized correctly.
    Attached Files
  9. #19
    Hi,

    I tried it, but the recursive property wasn't being copied over so it always became false.

    When I forced it to be true, I saw what the output was like (and as per the docs as well). But as you say this may make it more complex on the ASP side.

    Personally I'd be happy that if I had a complex object that I send it as json data instead of a post (with the implication then that the MVC controller can only have one parameter argument, which is not necessarily a bad thing itself).
  10. #20
    I tried it, but the recursive property wasn't being copied over so it always became false.
    Sorry for that. I changed the option's name a few times back and forth and, finally, left one name here, but another - there.

    But as you say this may make it more complex on the ASP side.
    So, is it not deserialized correctly?

    Personally I'd be happy that if I had a complex object that I send it as json data instead of a post (with the implication then that the MVC controller can only have one parameter argument, which is not necessarily a bad thing itself).
    Agree.
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 2
    Last Post: Oct 10, 2014, 8:50 AM
  2. Replies: 13
    Last Post: May 16, 2011, 1:26 PM
  3. [CLOSED] Adding params as jsonData for jsin Ajax requests
    By r_honey in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: May 06, 2010, 7:31 AM
  4. Ext.net.DirectMethod.request PARAMS
    By sipo in forum 1.x Help
    Replies: 0
    Last Post: Apr 15, 2010, 5:06 AM
  5. Page_ Ajax Load Complete BUG on Ajax Request
    By jeybonnet in forum 1.x Help
    Replies: 8
    Last Post: Jun 22, 2009, 11:19 AM

Posting Permissions