This method returns a bool and a string -
public (bool active, string name) Report()
{
}
From my controller, I call it like this -
public IActionResult Credit([FromBody] Data data)
{
return Ok(Report())
}
The response I get is something like this -
{
"item1": false,
"item2": "Your name"
}
How do I get this response instead -
{
"Active": false,
"Name": "Your name"
}
The quick and easy way would be to return an anonymous type, taking the values from the returned tuple
public IActionResult Credit([FromBody] Data data)
{
//...
var report = Report();
return Ok(new
{
Active = report.active,
Name = report.name
})
}
Ideally you should return a strongly typed model that can be returned from the API
public class ReportModel
{
public string Name { get;set; }
public bool Active { get;set; }
}
and update accordingly
public ReportModel Report()
{
//...
}
public IActionResult Credit([FromBody] Data data)
{
//...
var report = Report();
return Ok(report);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With