'C# ASP.Net Core how to return Json() response from an api controller
I currently have an asp.net core 2.2 webapi api controller. Returning Ok result with the response. But the requirement is to return Json() response.
[HttpGet]
[Route("employee/{employeeId}")]
public async Task<IActionResult> GetUserFromEmployeeNumber(string employeeId)
{
var correlationId = _correlationContextAccessor.CorrelationContext.CorrelationId;
try
{
var response = await _service.GetUserByEmployeeId(employeeId);
return Ok(response); //How to return Json().
}
catch (Exception exception)
{
return BadRequest(message);
}
}
For above, i get 204 No Content response if response is null.
Do i need to any reference package to use Json()? If so what is the correct package reference?
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
