Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Why can't I use [FromBody] in HttpGet?

$
0
0

this is my controller route config,

    [Produces("application/json")]
    [Route("/api/[controller]/[action]")]
    public class PatientsRegistrationController : Controller
    {.........

my HttpGet method looks like this,

 [HttpGet]
        public async Task<IActionResult> GetPatient([FromBody] KeyValueViewModel model)
        {
            if (!ModelState.IsValid)
            return BadRequest(ModelState);

            var patient = await repository.GetPatient(long.Parse(model.RequestId));
            ..................

I keep receiving this ModelState error,

{"": ["A non-empty request body is required."
  ]
}

Shall I use httpPost instead? or What am I doing wrong here?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>