Wednesday, 14 September 2016

How do i get ASP.Net Web API to return JSON

ASP.Net web api returns xml by default. But we can change so that it should return JSON instead of XML.

To do this open "WebApiConfig.cs" file and add below line :


Please look at below code sample:
public static void Register(HttpConfiguration config)
                name: "GetDataByID",
                routeTemplate: "api/ad/GetDataByID/{id}",
                defaults: new { Controller = "Test", Action = " GetDataByID " }


Now your web api will return JSON instead of XML.

No comments:

Post a Comment