How do I get ASP.NET Web API to return JSON instead of XML?


 Just add the following in App_Start/WebApiConfig.cs class in MVC  Web API project.
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html") );

That makes sure you get json on most queries, but you can get xml when you send text/xml.

Comments

Popular posts from this blog

Validate Mobile Number with 10 Digits in ASP.Net