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!