当前位置: 首页>>代码示例>>C#>>正文


C# this.AddModelError方法代码示例

本文整理汇总了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();
        }
开发者ID:jd-pantheon,项目名称:Titan-Framework-v2,代码行数:13,代码来源:ModelStateDictionaryExtensions.cs

示例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;
 }
开发者ID:peasy,项目名称:Samples,代码行数:11,代码来源:ModelStateDictionaryExtensions.cs

示例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;
 }
开发者ID:fmichellonet,项目名称:MVCArch,代码行数:13,代码来源:ModelStateDictionaryExtensions.cs

示例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 : ""));
     }
 }
开发者ID:LeMinhHiep,项目名称:BPortals,代码行数:20,代码来源:ControllersExtensions.cs

示例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);
     }
 }
开发者ID:niallduane,项目名称:Yummy.Questionaire,代码行数:11,代码来源:ModelState.cs

示例6: AddModelErrors

 public static void AddModelErrors(this ModelStateDictionary state, IEnumerable<ValidationError> errors)
 {
     foreach (var error in errors)
     {
         state.AddModelError(error.PropertyName, error.ErrorMessage);
     }
 }
开发者ID:victorblaga,项目名称:Document-Management,代码行数:7,代码来源:ModelStateExtensions.cs

示例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));
     }
 }
开发者ID:jespinoza711,项目名称:ASP.NET-MVC-CMS,代码行数:12,代码来源:ModelStateExtensions.cs

示例8: FillDataViolation

 public static void FillDataViolation(this ModelStateDictionary modelState, IEnumerable<DataViolationItem> violations)
 {
     foreach (var issue in violations)
     {
         modelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
     }
 }
开发者ID:Kooboo,项目名称:CommonLibraries,代码行数:7,代码来源:ModelStateExtensionMethods.cs

示例9: AddErrorsFromIdentiyResult

 public static void AddErrorsFromIdentiyResult(this ModelStateDictionary modelState, IEnumerable<string> resultErrors)
 {
     foreach (string error in resultErrors)
     {
         modelState.AddModelError("", error);
     }
 }
开发者ID:WhistlerHusky,项目名称:Journal,代码行数:7,代码来源:ModelStateHelper.cs

示例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;
 }
开发者ID:rodmjay,项目名称:Ideal,代码行数:13,代码来源:ModelStateExtensions.cs

示例11: AgregarErrores

 public static void AgregarErrores(this ModelStateDictionary estado, Resultado resultado)
 {
     foreach (var error in resultado.Errores)
     {
         estado.AddModelError(error.Key, error.Value);
     }
 }
开发者ID:aaolivera,项目名称:LinkGamer,代码行数:7,代码来源:ExtensionesModelState.cs

示例12: ApplyValidationFailures

 public static void ApplyValidationFailures(this ModelStateDictionary state, IList<ValidationFailure> validationFailures)
 {
     foreach(var failure in validationFailures)
     {
         state.AddModelError(failure.PropertyName, failure.ErrorMessage);
     }
 }
开发者ID:psmyrdek,项目名称:it-learning,代码行数:7,代码来源:ModelStateExtensions.cs

示例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);
     }
 }
开发者ID:mingzhichen,项目名称:quartznet-admin,代码行数:7,代码来源:ControllerHelpers.cs

示例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;
        }
开发者ID:rtennys,项目名称:Toph,代码行数:7,代码来源:ModelStateDictionaryExtensions.cs

示例15: AddRuleErrors

 public static void AddRuleErrors(this ModelStateDictionary modelState, RulesException ex)
 {
     foreach (var x in ex.Errors)
     {
         modelState.AddModelError(x.PropertyName, x.ErrorMessage);
     }
 }
开发者ID:chiqua25,项目名称:icsyweb,代码行数:7,代码来源:ControllerExtensions.cs


注:本文中的this.AddModelError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。