Handle Form Submissions with JSON
mainBecause Inertia sends request data as JSON, you must decorate your model parameters with [FromBody] in your controller actions. Validation errors are automatically passed back to the frontend by the adapter.
[HttpPost]
public async Task<IActionResult> Create([FromBody] Post post)
{
if (!ModelState.IsValid)
{
// The validation errors are passed automatically.
return await Index();
}
_context.Add(post);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}