Jan 13, 2015, 4:33 PM
[CLOSED] [#636] Difference between DirectMethod request params and Ajax request params
Hi,
I think Arrays are not being submitted in the same way for DirectMethod requests as they are for Ajax requests:
Consider this (the URL that direct method or ajax request is going to doesn't matter - it can fail, it is the HTTP post that is significant)
application/x-www-form-urlencoded
Now if you run the same with Ajax:
application/x-www-form-urlencoded
This is quite significant for me in a certain scenario.
Is there any way Direct Method can be configured to send params in the way that Ext.Ajax.request is doing when using params when some of the params (complex objects) contains arrays?
Reason this is important for me is that it makes it consistent, especially for those coming in from a pure Ext JS background and also works better with ASP.NET MVC Controllers that use plain old C# objects as controller argument. In other words the type of the argument is a class that has many properties including things like List<int> in the type definition. ASP.NET MVC automatically binds such variables to these if they are sent, as seen by the Ext.Ajax.request approach. When I am using a DirectMethod like above it becomes null because MVC cannot deserialize.
To clarify, if I have a C# object like this:
I think Arrays are not being submitted in the same way for DirectMethod requests as they are for Ajax requests:
Consider this (the URL that direct method or ajax request is going to doesn't matter - it can fail, it is the HTTP post that is significant)
var params = {
a: 1,
b: [1, 2, 3]
};
Now, if I submit via direct method:Ext.net.DirectMethod.request({
url: '/does/not/matter',
cleanRequest: true,
params: params
})
Look at the HTTP request, and you will see params are sent like this:application/x-www-form-urlencoded
Parameters | |
a | 1 |
b | [1,2,3] |
Raw | |
a=1&b=%5B1%2C2%2C3%5D |
Now if you run the same with Ajax:
Ext.Ajax.request({
url: '/does/not/matter',
method:'post',
params:params,
});
You get this:application/x-www-form-urlencoded
Parameters | |
a | 1 |
b | 1 |
b | 2 |
b | 3 |
Raw | |
a=1&b=1&b=2&b=3 |
This is quite significant for me in a certain scenario.
Is there any way Direct Method can be configured to send params in the way that Ext.Ajax.request is doing when using params when some of the params (complex objects) contains arrays?
Reason this is important for me is that it makes it consistent, especially for those coming in from a pure Ext JS background and also works better with ASP.NET MVC Controllers that use plain old C# objects as controller argument. In other words the type of the argument is a class that has many properties including things like List<int> in the type definition. ASP.NET MVC automatically binds such variables to these if they are sent, as seen by the Ext.Ajax.request approach. When I am using a DirectMethod like above it becomes null because MVC cannot deserialize.
To clarify, if I have a C# object like this:
public class MyClass
{
int a { get; set; }
List<int> b { get; set; }
}
Then my Controller signature can take an argument of type MyClass as the parameter, but b will be null...
Last edited by Daniil; Jan 17, 2015 at 10:43 AM.
Reason: [CLOSED]