c# - Setting the Default JSON Serializer in ASP.NET MVC -


i'm having hard time finding answer this:

i'm working on existing application has been partially converted on mvc. whenever controller responds json actionresult, enums sent numbers opposed string name. sounds default serializer should json.net, should sending enums on names opposed integer representation, that's not case here.

am missing web.config setting sets default serializer? or there setting needs changed?

in asp.net mvc4 default javascript serializer used in jsonresult class still javascriptserializer (you can check in code)

i think have confused asp.net web.api json.net default js serializer mvc4 doesn't use it.

so need configure json.net work mvc4 (basically need create own jsonnetresult), there plenty of articles it:

if want use json.net controller action parameters during model binding need write own valueproviderfactory implementation.

and need register implementation with:

valueproviderfactories.factories     .remove(valueproviderfactories.factories                                   .oftype<jsonvalueproviderfactory>().single()); valueproviderfactories.factories.add(new myjsonvalueproviderfactory()); 

you can use built in jsonvalueproviderfactory example or article: asp.net mvc 3 – improved jsonvalueproviderfactory using json.net


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -