0

Here is my controller...

public class AccountController : BaseController
{
    [Route("Account/json_account_log_in")]
    public async Task<JsonResult> json_account_log_in(ValidateUserQuery query)
    {
        ValidateUserDto response = await Mediator.Send(query);
        // Do stuf...
    }
}

And here is the query class..

public class ValidateUserQuery : IRequest<ValidateUserDto>
{
    public string Username { get; set; }
    public string Password { get; set; }    
}

But in my controller, the query Username and Password are null.

If I remove the IRequest<ValidateUserDto> then Username and Password are correct - but then I can't use Mediatr.

Can't I use classes that inherits from IRequest in ajax calls queries?

MojoDK
  • 4,410
  • 10
  • 42
  • 80

1 Answers1

0

Solution ... I needed to add [FromBody]:

public async Task<JsonResult> json_account_log_in([FromBody] ValidateUserQuery query)
MojoDK
  • 4,410
  • 10
  • 42
  • 80
  • Glad to hear you resolved the issue. Besides, if you apply `[ApiController]` attribute to your AccountController class, it would also work well without specifying `[FromBody]`. – Fei Han Mar 13 '20 at 07:47