I currently have a view component which contains a form. Once this form is submitted it is sent to the controller and the model state is checked. Normally after the model state is not valid I just reload the view with the model passed in and display the values in the with the validation error messages. My issue is because I'm using a view component how do I get this model with the validation error messages back to the view component from the controller. I need to get them model through the view and to the view component.
Say that I submit the form with data that would fail model validation and the controller method below is hit, after the model state is checked and fails, how would I return it back to the view component?
public async Task<IActionResult> UpdateDetails(CustomerDetailsViewModel customerDetailsViewModel)
{
if (ModelState.IsValid)
{
...
}
//How to return 'customerDetailsViewModel' back to view component
}