예제 #1
0
 /// <summary>Returns a list of all error messages within a ModelState for the given property</summary>
 public static List <string> ErrorMessagesFor(this ModelStateDictionary modelState, string propertyName)
 {
     try {
         return(modelState.ErrorMessagesForAll()[propertyName]);
     } catch (KeyNotFoundException) {
         return(new List <string>());
     }
 }
예제 #2
0
        /// <summary>Returns all of the error message for the provided ModelState (just the messages - not the properties)</summary>
        public static List <string> ErrorMessages(this ModelStateDictionary modelState)
        {
            var all = new List <string>();

            foreach (var error in modelState.ErrorMessagesForAll())
            {
                all.AddRange(error.Value);
            }
            return(all);
        }