Hi there,
We've hit a weird problem with passing a complex class in web api 2. The class looks like this:
MyClass
{
public integer PageNumber {get; set;}
public integer RowsPerPage {get; set;}
public dynamic Parameters {get; set;}
public dynamic OrderBy {get; set;}
}
This is then used as a parameter in a Controller GET method with a "FromUri" attribute.
Now the weird thing is, the dynamic Parameters never gets deserialised. The debugger just calls it "Object" and won't open it up. Parameters contains filter parameters for SQL, eg:
{
"NameFilter":"A%",
"MinAgeFilter": 18
}
I've tried swapping dynamic with a JObject, but I think that's dynamic too; a dictionary also comes out empty.
If I take each of the Parameters and add them into the controller method, I get a 400 returned.
Questions:
a) Is it possible to use dynamics in web api controller parameters? Is there some special way of formatting the Json at the client for dynamic parameters?
b) How is it possible to mix simple types with objects in controller functions, eg this gets an invalid request returned:
[Route("mydata/page/{pagenumber}")]
public Get(int pagenumber, [FromUri] PagingParams request,
[FromUri] string NameFilter,[FromUri] int MinAgeFilter)
The (unescaped) URI generated from JQuery for that looks something like:
mydata/page/1?request[PageNumber]=1&request[RowsPerPage]=20&request[OrderBy]=&NameFilter=A%&MinAgeFilter=18
which throws an invalid request and with the parameters inside PagingParams, something like this:
mydata/page/1?request[PageNumber]=1&request[RowsPerPage]=20&request[Parameters][NameFilter]=A%&request[Parameters][MinAgeFilter]=18&request[OrderBy]=
...which gets to the controller method, but Parameters doesn't contain anything.
It all seems a bit strange. Obviously I can just split out PagingParams into separate parameters, probably working that into the route, but I'm intrigued to know what the rules are around this.
Any thoughts?
Thanks,
Thanks, R