Kooboo / CMS

Old Kooboo CMS, Use Kooboo/Kooboo instead.
http://www.kooboo.com
Other
337 stars 224 forks source link

issue in Json_netModelBinder.cs #129

Open aruss opened 11 years ago

aruss commented 11 years ago

I found an issue in JSON model binder, it desterilized the request data always to Newtonsoft.Json.Linq.JObject and caused invalid entry for parameter exception. By providing the model type from model metadata fixed the problem.

// Use the built-in serializer to do the work for us
return JsonConvert.DeserializeObject(jsonStringData, 
    bindingContext.ModelMetadata.ModelType, 
    new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });

Cheers aruss

kooboo-jifeng commented 11 years ago

Thanks

BTW, the Json_netModelBinder only be applied when the content type is "application/json_net".

https://github.com/Kooboo/CMS/blob/master/Kooboo.CMS/Kooboo.CMS.Web/Models/Json_netModelBinder.cs

aruss commented 11 years ago

I think to use "application/json_net" content type is inappropriate way to do it, in this case all the already developed javascripts has to be changes to this content type.

It would be better if it would handle all application/json requests because there is no difference.

The problem is, if you use default MVC actions and trying to parse a model, Kooboo don't bind them. The same code works perfectly in a empty, new MVC solution (without Kooboo). But if you use the Json_netModelBinder (Newtonsoft.Json) it works perfectly.

Cheers aruss

kooboo-jifeng commented 11 years ago

yes, one developer had reported he can not bind the json to his model via Json.net. So I changed the json net only handle the content type is "application/json_net", then he works fine. I will test it again with your advice, it if get wok, I will change the content type back to "application/json".

Thank your very much!