My controller's methods in Blazor's server side WebApi returns an html/text response instead of application/json which leds to
The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'.
error. What is the best way to manually set the content type of the response to application/json?
My Controller with a Get method
[Route("api/[controller]")]
[ApiController]
public class DeveloperController : ControllerBase
{
private readonly ApplicationDBContext _context;
public DeveloperController(ApplicationDBContext context)
{
_context = context;
}
[HttpGet]
public async Task<ActionResult> Get()
{
var devs = await _context.Developers.ToListAsync();
return Ok(devs);
}
and the call from Client side page
developers = await client.GetFromJsonAsync<Developer[]>("api/developer");
Thanks for all the answers, and as always, happy coding!