public void ActionForDataAnnotationLocalization(AnnotatedExampleModel model) { if (!ModelState.IsValid) { var key = nameof(AnnotatedExampleModel.Value); foreach (var error in ModelState[key].Errors) { _logger.LogInformation($"Localized validation error message: {error.ErrorMessage}"); } } }
public IActionResult SetExampleWithInputModel(AnnotatedExampleModel model) { if (!ModelState.IsValid) { foreach (var error in ModelState.SelectMany(kvp => kvp.Value.Errors.Select(err => new { kvp.Key, Message = err.ErrorMessage }))) { _logger.LogInformation($"Error at {error.Key}: {error.Message}"); } return(BadRequest(ModelState)); } return(NoContent()); }