I have the following code:
protected IEnumerable<string> GetErrorsFromModelState() {
var exceptions = ModelState.SelectMany(x => x.Value.Errors
.Select(error => error.Exception.Message));
var errors = ModelState.SelectMany(x => x.Value.Errors
.Select(error => error.ErrorMessage));
return exceptions.Union(errors);
}
Is there a way that I could stop this giving a nullReference Exception if:
error.Exception is null or if error.Exception.Message is null
Both cases are giving me problems and I'm not sure how I can code this with a IsNullOrEmpty check for both cases.