I used to have an action processing some complex JSON data:
[HttpPost, ValidateAntiForgeryToken]
public ActionResult GetAdditionals(string pageIdentifier,
IEnumerable<HtmlPlaceHolder> htmlPlaceHolders,
IEnumerable<DataSource> dataSourceRequests)
that was called from client side like this:
var requestData = {
pageIdentifier: 'test',
htmlPlaceHolders: getHtmlPlaceHolders(),
dataSourceRequests: getDataSourceRequests(),
__RequestVerificationToken: token
};
$.post(url, $.toDictionary(requestData), resultHandler, "json");
Where htmlPlaceHolders and dataSourceRequests would contain arrays of objects matching the classes shown in the signature of the action method.
$.toDictionary() is used to get the complex object to the server in a proper manner.
That was all working fine. But now I want to do some processing of the same post data in an ActionFilter. Therefore, in the OnActionExecuting methode, I want to parse the data in the NameValueCollection contained in filterContext.HttpContext.Request.Form where the names of the name/value pairs look like:
pageIdentifier
htmlPlaceHolders[0].ControlId
htmlPlaceHolders[0].FunctionName
htmlPlaceHolders[0].Parameter
...
...
dataSourceRequests[0].Id
dataSourceRequests[0].Src
Now I need to know how I can reconstruct the IEnumerable<HtmlPlaceHolder> and IEnumerable<DataSource> from this NameValueCollection like the default model binder did for my action. So far, I cannot figure out a nice way to accomplish this.