jsonblazormediatr

Blazor The input does not contain any JSON tokens


I am trying to pass an order number to Mediator to look up.

Here are examples of order numbers:

GRE_A14Y9-TS72
ANN_ALJB6-E6ZN

In localhost, I am passing them on the url like this:

https://localhost:44318/Application/Workorder/ABC_A14Y9-TS78

In my Razor page, my call is here:

private async Task Lookup()
{
    var orderNumber = request.OrderNumber;
    var path = $"api/workorder/{_model.OrderNumber}";
    var response = await _apiService.GetFromJsonAsync<WorkorderDTO>(path, CancellationToken.None);
    return response;
}

The code above fails on the call to GetFromJsonAsync.

On the API side, I have the lookup, but it is never getting called. Instead, I get the error that the input does not contain any JSON tokens.

Is there an issue with the formatting of the Order Numbers?

Here is the API code for my HttpGet, but that breakpoint is never reached:

[ApiController]
[Route("api/application/workorder")]
[Tags("AM Application Data")]
public class WorkorderController : ControllerBase
{
    private readonly IMediator _mediator;

    public WorkorderController(IMediator mediator)
    {
        _mediator = mediator;
    }

    [HttpGet]
    public async Task<IActionResult> Get([FromRoute] string orderNumber)
    {
        var request = new Workorder.Request()
        {
            Name = "Work Order",
            OrderNumber = orderNumber,
        };
        var response = await _mediator.Send(request);
        return Ok(response);
    }
}

Solution

  • Compare

    var path = $"api/workorder/{_model.OrderNumber}";
    

    and

    [Route("api/application/workorder")]
    

    They don't match.

    You will have more success with

    [Route("api/{controller}")]
    

    although there are some other issues in your code. What is the connection between request.OrderNumber and _model.OrderNumber ?