// If any Model rules broken, set SelectedCommonDataType Errors collection // which are data bound to UI error textblocks. private void DisplayPhoneCallErrorMessages(ModelValidationResult modelValidationResult) { var phoneCallUpdateErrors = new Dictionary<string, ReadOnlyCollection<string>>(); // Property keys format: address.{Propertyname} foreach (var propkey in modelValidationResult.ModelState.Keys) { string propertyName = propkey.Substring(propkey.IndexOf('.') + 1); // strip off order. prefix // 'modelValidationResults.ModelState[propkey]' is the collection of string error messages // for the property. Later on in UILayer, FirstErrorConverter will display the one of the collection. // 'propertyName' will only occur once for each property in the Model so a new ReadOnlyCollection // can be created on each pass of the foreach loop. phoneCallUpdateErrors.Add(propertyName, new ReadOnlyCollection<string>(modelValidationResult.ModelState[propkey])); } if (phoneCallUpdateErrors.Count > 0) { SelectedPhoneCall.Errors.SetAllErrors(phoneCallUpdateErrors); } }
public ModelValidationException(ModelValidationResult validationResult) { ValidationResult = validationResult; }