I have the following action that is returning an Ilist, when returning data it results in an Empty Json:
[
{}
]
the apicontroller method is like this;
[HttpGet]
public IHttpActionResult ConsultaPuertos([FromUri] string id,
[FromBody] List<PuertosGP> lstPuertosGP, [FromUri] DateTime fecha)
{
var resultList1 = puertosGPRepository.ConsultaPuertos(id, lstPuertosGP,
fecha);
return Ok(resultList1);
});
Is it feasible to send a Json(resultList1)? or make the action return not an IList but a JsonResult?
UPDATE In the step by step it is observed that at least one record returns from the portsGPRepository(...)
in the POSTMAN the json is empty
UPDATE 2
I have changed in my WebApiConfig.cs
I have this line:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Configuración y servicios de API web
// Web API configuration and services
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));//text/html
First of all the method has to be GET , since you are doing a query/request, POST methods are for publishing/saving information. That is, change
[HttpPost]
to[HttpGet]
, you also need to place the await in the query made in resultList1, since you defined the method as async , that is, you will have it.The IHttpActionResult methods are generally used in APIs since they allow you to return a
return Content
with more query specifications, I also recommend changing the method signatureTask<IList<PuertosGP>>
toTask<List<PuertosGP>>
.