I have the following code snippets.
protected IEnumerable<string> GetErrorsFromModelState()
{
var errors = ModelState.SelectMany(x => x.Value.Errors
.Select(error => error.ErrorMessage));
return errors;
}
protected IEnumerable<string> GetErrorsFromModelState()
{
var exceptions = ModelState.SelectMany(x => x.Value.Errors
.Select(error => error.Exception));
return exceptions;
}
Is there a way that I could combine these two so that GetErrorsFromModelState will return all the ErrorMessage and Exception values?
Sure – use the Enumerable.Union extension method