I have the following code:
protected IEnumerable<string> GetErrorsFromModelState() {
var errors = ModelState
.SelectMany(x => x.Value.Errors.Select(error => error.ErrorMessage)
.Union(x.Value.Errors.Select(error => error.Exception.Message)));
return errors;
}
It works but when there is an entry for ErrorMessage of “” then it adds this to the list of strings. Is there a way that I could make it only select ErrorMessages if they are not “” ?
Try to check for the empty string, if it is null or empty discard the select and projection.