I am trying some paging and sorting stuffs in ASP.net core MVC 6 application. But when I pass array like query string MVC action unable to parse it to list.
Query String looks like :
take=10&skip=0&page=1&pageSize=10&sort%5B0%5D%5Bfield%5D=price&sort%5B0%5D%5Bdir%5D=asc
Model for it looks like:
This is the query string which i am getting at server:
Count for Sort Array or List is always 0.
Can you please suggest a work around. It should parse it correctly but not getting where things are wrong.
Someone may have a better answer, but if it were me I'd simplify my query string a bit and flatten the model. So the query string might be:
take=10&skip=0&page=1&pageSize=10&sortfield1=price&sortdir1=asc&sortfield2=otherfield&sortdir2=desc
Then in the model replace
public List<Sort> Sort
with the flattened properties:You can add as many of these flattened properties as needed. It's not elegant, but it gets the job done. Then if you need your Sort list built you can build it from these properties easily.