I am using ASP.net web API 2.0 and would like my method to return the data in JSON format only.
Please suggest the code changes for this below method from the API controller class.
public async Task<List<Partner>> GetPartnerList()
{
return await _context.Partners.Take(100).ToListAsync();
}
You can use the
Json<T>(T content)
method of theApiController
refactor action to return
IHttpActionResult
abstraction, await the data and pass it to theJson
method which returns aJsonResult
.This means that regardless of content negotiation, the above action will only return JSON data.