Pages - Menu

%5B%5D issue when binding JSON Array to MVC Model

Had some issues during a post back of JSON object from the MVC View to the Controller by jQuery Ajax. To be precise, I am actually using Telerik Control that utilize jQuery Ajax. One of the IList<string> property is not populated in the model.


With the help of firebug, the JSON post back of the array has this extra %5B%5D in the name of the fields. Thus MVC framework couldn't map it to the property.


It takes one magic line of code for the JSON post back not to include this extra URL encoded characters in the field name. It is documented in the jQuery API

$.ajaxSettings.traditional = true;

Now the post back is correct and the MVC model can be populated.

No comments:

Post a comment