I am trying to make Blazor APP that returns Employees list but when trying to return the list using GetJsonAsync the following error appears ....
JsonException: '<' is an invalid start of a value. Path: $ | LineNumber: 1 | BytePositionInLine: 0.
Controller Files:
[ApiController]
[Route("[controller]")]
public class EmployeesController : ControllerBase
{
private readonly IEmployeeRepository employeeRepository;
public EmployeesController(IEmployeeRepository employeeRepository)
{
this.employeeRepository = employeeRepository;
}
[HttpGet]
public async Task<ActionResult> GetEmployees()
{
try
{
return Ok(await employeeRepository.GetEmployees());
}
catch (Exception)
{
return StatusCode(StatusCodes.Status500InternalServerError
,"Error retrieving data from the database");
}
}
Services Class:
public async Task<IEnumerable<Employee>> GetEmployees()
{
return await httpClient.GetJsonAsync<Employee[]>("employees");
}
Blazor Base Class:
public class EmployeeListBase : ComponentBase
{
[Inject]
IEmployeeService EmployeeService { get; set; }
public IEnumerable<Employee> Employees { get; set; }
protected override async Task OnInitializedAsync()
{
Employees = (await EmployeeService.GetEmployees()).ToList();
}
}