The following jQuery code:
$.param({
Parts: [{ hasLabel: "label", hasType: "type", hasIndex : 1 }],
LastKey : "LastKey",
Term : "Term"
})
gives the following output:
"Parts%5B0%5D%5BhasLabel%5D=label&Parts%5B0%5D%5BhasType%5D=type&Parts%5B0%5D%5BhasIndex%5D=1&LastKey=LastKey&Term=Term"
which decodes to (using decodeURI()) :
"Parts[0][hasLabel]=label&Parts[0][hasType]=type&Parts[0][hasIndex]=0&LastKey=LastKey&Term=Term"
However, the default model binder in MVC expects the following:
"Parts[0].hasLabel=label&Parts[0].hasType=type&Parts[0].hasIndex=0&LastKey=LastKey&Term=Term"
I'm looking for a Javascript Regex to coerce the encoded string into a (still encoded) string , but one that decodes to the correct model binding convention.