Is there a way to access validation error messages in the controller. I'm not finding them anywhere in ModelState.
Iterating over ModelState is used for this purpose. Something along these lines:
if (!ModelState.IsValid)
{
    StringBuilder result = new StringBuilder();
    foreach (var item in ModelState)
    {
        string key = item.Key;
        var errors = item.Value.Errors;
        foreach (var error in errors)
        {
            result.Append(key + " " + error.ErrorMessage);
        }
    }
    TempData["Errors"] = result.ToString();
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With