Tuesday, February 12, 2019

View all model state errors while debugging

If we are in break mode while debugging an MVC controller event,  and want to view all ModelState errors, the following command can show all error messages in immediate window:


ModelState.Where(x => x.Value.Errors.Count>0).SelectMany((x, i)=> x.Value.Errors.Select(y=> "Key: " + x.Key + ", Error: " + y.ErrorMessage)).ToList()

No comments:

Regex obfuscate email

 Use this code in C# to obfuscate email using regex // Online C# Editor for free // Write, Edit and Run your C# code using C# Online Compile...