Answer the question
In order to leave comments, you need to log in
How to send an object as a POST request in ASP.NET?
I have a controller:
[ApiController]
[Route("api")]
public class HomeController : ControllerBase
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
[HttpGet("login")]
public IActionResult Get()
{
return Ok(new { id = 1 });
}
[HttpPost("logout")]
public IActionResult Return()
{
return Ok(new { object });
}
}
req.body,
how can I do it?
Answer the question
In order to leave comments, you need to log in
In the Return() parameters, specify the object handle to be passed.
It can be:
Return(int id)
or a class describing json, for example:
[HttpPost]
[Produces("application/json")]
public IActionResult Return([FromBody] InPOST form)
where
public class InPOST
{
public int id { get ; set; }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question