本文整理汇总了C#中this.AddModelError方法的典型用法代码示例。如果您正苦于以下问题:C# this.AddModelError方法的具体用法?C# this.AddModelError怎么用?C# this.AddModelError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.AddModelError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyValidationErrors
/// <summary>
/// Copies the validation errors.
/// </summary>
/// <param name="modelState">State of the model.</param>
/// <param name="validationErrors">The validation errors.</param>
public static void CopyValidationErrors(this ModelStateDictionary modelState, IList<ValidationError> validationErrors)
{
validationErrors.ForEach(error => modelState.AddModelError(error.Property, /* strValue, */ error.Message));
//string strValue = null;
//if (error.AttemptedValue != null)
// strValue = error.AttemptedValue.ToString();
}
示例2: ThenAddRange
public static ModelStateDictionary ThenAddRange(this ModelStateDictionary modelState, IEnumerable<ValidationResult> validationResults)
{
foreach (var error in validationResults)
{
if (error.MemberNames.Any())
modelState.AddModelError(error.MemberNames.First(), error.ErrorMessage);
else
modelState.AddModelError(string.Empty, error.ErrorMessage);
}
return modelState;
}
示例3: MergeWithValidatableObject
public static ModelStateDictionary MergeWithValidatableObject(this ModelStateDictionary modelState, IValidatableObject obj)
{
IEnumerable<ValidationResult> errors = obj.Validate(new ValidationContext(obj, null, null));
foreach (ValidationResult error in errors)
foreach (string memberName in error.MemberNames)
{
if (modelState.ContainsKey(memberName))
modelState.AddModelError(memberName, error.ErrorMessage);
else
modelState.AddModelError(memberName, error.ErrorMessage);
}
return modelState;
}
示例4: AddValidationErrors
/// <summary>
/// Add to the model state a list of error that came from properties. If the property name
/// is empty, this one will be without property (general)
/// </summary>
/// <param name="modelState">State of the model.</param>
/// <param name="propertyErrors">The property errors.</param>
public static void AddValidationErrors(this ModelStateDictionary modelState, Exception exception)
{
if (exception is IValidationErrors)
{
foreach (var databaseValidationError in (exception as ValidationErrors).Errors)
{
modelState.AddModelError(databaseValidationError.PropertyName ?? string.Empty, databaseValidationError.PropertyExceptionMessage);
}
}
else
{
modelState.AddModelError(string.Empty, exception.Message + (exception.Message != exception.GetBaseException().Message ? "\r\n" + exception.GetBaseException().Message : ""));
}
}
示例5: AddModelErrors
/// <summary>
/// Adds the list of errors to the Model State Dictionary.
/// </summary>
/// <param name="errors"></param>
public static void AddModelErrors(this System.Web.Mvc.ModelStateDictionary state, IList<Models.ValidationResult> errors)
{
foreach (var item in errors)
{
state.AddModelError(item.Name, item.Message);
}
}
示例6: AddModelErrors
public static void AddModelErrors(this ModelStateDictionary state, IEnumerable<ValidationError> errors)
{
foreach (var error in errors)
{
state.AddModelError(error.PropertyName, error.ErrorMessage);
}
}
示例7: AddErrors
/// <summary>
/// Add errors from entity to the model state.
/// </summary>
/// <param name="modelState"></param>
/// <param name="entity"></param>
public static void AddErrors(this ModelStateDictionary modelState, IErrors errors)
{
if (errors.Count > 0)
{
errors.EachFull(err => modelState.AddModelError("", err));
}
}
示例8: FillDataViolation
public static void FillDataViolation(this ModelStateDictionary modelState, IEnumerable<DataViolationItem> violations)
{
foreach (var issue in violations)
{
modelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
}
}
示例9: AddErrorsFromIdentiyResult
public static void AddErrorsFromIdentiyResult(this ModelStateDictionary modelState, IEnumerable<string> resultErrors)
{
foreach (string error in resultErrors)
{
modelState.AddModelError("", error);
}
}
示例10: Process
/// <summary>
/// Processes the specified model state.
/// </summary>
/// <param name="modelState">State of the model.</param>
/// <param name="result">The result.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
public static bool Process(this ModelStateDictionary modelState, IValidationContainer result)
{
foreach (var r in result.ValidationErrors)
foreach (var e in r.Value)
modelState.AddModelError(r.Key, e);
return modelState.IsValid;
}
示例11: AgregarErrores
public static void AgregarErrores(this ModelStateDictionary estado, Resultado resultado)
{
foreach (var error in resultado.Errores)
{
estado.AddModelError(error.Key, error.Value);
}
}
示例12: ApplyValidationFailures
public static void ApplyValidationFailures(this ModelStateDictionary state, IList<ValidationFailure> validationFailures)
{
foreach(var failure in validationFailures)
{
state.AddModelError(failure.PropertyName, failure.ErrorMessage);
}
}
示例13: AddRuleViolations
public static void AddRuleViolations(this ModelStateDictionary modelState, IEnumerable<RuleViolation> ruleViolations)
{
foreach (RuleViolation ruleViolation in ruleViolations)
{
modelState.AddModelError(ruleViolation.PropertyName ?? Guid.NewGuid().ToString(), ruleViolation.ErrorMessage);
}
}
示例14: AddModelErrors
public static ModelStateDictionary AddModelErrors(this ModelStateDictionary modelState, CommandResult result)
{
foreach (var error in result.Errors)
modelState.AddModelError(error.Key, error.Error);
return modelState;
}
示例15: AddRuleErrors
public static void AddRuleErrors(this ModelStateDictionary modelState, RulesException ex)
{
foreach (var x in ex.Errors)
{
modelState.AddModelError(x.PropertyName, x.ErrorMessage);
}
}