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


C# ModelStateDictionary.Where方法代码示例

本文整理汇总了C#中ModelStateDictionary.Where方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.Where方法的具体用法?C# ModelStateDictionary.Where怎么用?C# ModelStateDictionary.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelStateDictionary的用法示例。


在下文中一共展示了ModelStateDictionary.Where方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetErrors

        private Dictionary<string, ModelErrorCollection> GetErrors(ModelStateDictionary modelState)
        {
            var errors = modelState.Where(x => x.Value.Errors.Any())
                                        .Select(x => new { x.Key, x.Value.Errors })
                                        .ToDictionary(o => o.Key, o => o.Errors);

            return errors;
        }
开发者ID:smagne87,项目名称:iCatalogProject,代码行数:8,代码来源:BaseController.cs

示例2: UpdateMatchResponseViewModel

 public UpdateMatchResponseViewModel(bool success, string message, ModelStateDictionary modelState)
     : this(success, message)
 {
     var results = new List<ValidationResultViewModel>();
       foreach (var result in modelState.Where(kvp => kvp.Value.Errors.Count > 0)) {
     results.Add(new ValidationResultViewModel(result));
       }
       ValidationResults = results;
 }
开发者ID:pwideman,项目名称:ClubPool,代码行数:9,代码来源:ViewModels.cs

示例3: Merge

		/// <summary>
		/// Merges ModelState that has names matching the prefix
		/// </summary>
		/// <param name="state"></param>
		/// <param name="dictionary"></param>
		/// <param name="prefix"></param>
		public static void Merge(this ModelStateDictionary state, ModelStateDictionary dictionary, string prefix)
		{
			if (dictionary == null)
				return;
			foreach (var keyValuePair in dictionary.Where(keyValuePair => keyValuePair.Key.StartsWith(prefix + ".")))
			{
				state[keyValuePair.Key] = keyValuePair.Value;
			}
		}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:15,代码来源:ModelStateExtensions.cs

示例4: AddRedirectMessage

 protected void AddRedirectMessage(ModelStateDictionary state)
 {
     foreach (var stm in state.Where(stm => stm.Value.Errors != null))
     {
         this.AddRedirectMessages(
             stm.Value.Errors.Select(
                 e => new ServerResponse(ServerResponseStatus.ERROR, e.ErrorMessage, e.Exception.Message))
                 .ToArray());
     }
 }
开发者ID:mitsbits,项目名称:Ubik.MVC5,代码行数:10,代码来源:BackOfficeController.cs

示例5: Error

 public static JsonResult Error(ModelStateDictionary modelState)
 {
     return new JsonResult()
     {
         Data = new
         {
             Success = false,
             Errors =
         modelState.Where(ms => ms.Value.Errors.Count > 0).Select(
             ms =>
             new { Field = ms.Key, Error = ms.Value.Errors.First().ErrorMessage })
         },
         JsonRequestBehavior = JsonRequestBehavior.AllowGet
     };
 }
开发者ID:CodeGarten,项目名称:CodeGarten,代码行数:15,代码来源:Utils.cs

示例6: MakeHierarchical

 public static PropertyError MakeHierarchical(ModelStateDictionary modelStateDictionary)
 {
     var root = new PropertyError();
     foreach(var kvp in modelStateDictionary.Where(kvp => kvp.Value.Errors.Count > 0))
     {
         PropertyError current = root;
         foreach(string property in kvp.Key.Split('.', '[', ']').Where(k => k != ""))
         {
             int index;
             current = int.TryParse(property, out index) ? current[index] : current[property];
         }
         foreach(ModelError modelError in kvp.Value.Errors)
         {
             current.Errors.Add(modelError);
         }
     }
     return root;
 }
开发者ID:gimmi,项目名称:randomhacking,代码行数:18,代码来源:ValidationHelpers.cs

示例7: GetFormErrors

        protected SubmitFormErrors GetFormErrors(ModelStateDictionary modelState)
        {
            SubmitFormErrors formErrors = null;

            if (!modelState.IsValid)
            {
                var errorsDictionary = new Dictionary<string, string>();

                foreach (var error in modelState.Where(f => f.Value.Errors.Count > 0))
                {
                    var errorMessage = error.Value.Errors.First();
                    errorsDictionary.Add(error.Key, errorMessage.ErrorMessage);
                }

                formErrors = new SubmitFormErrors(errorsDictionary);
            }

            return formErrors;
        }
开发者ID:alt-soft,项目名称:vc-community,代码行数:19,代码来源:StoreControllerBase.cs

示例8: Fail

        /// <summary>
        /// JSend spec: "There was a problem with the data submitted, or some pre-condition of the API call wasn't satisfied"
        /// Creates message data based on validation errors.
        /// </summary>
        public static JsonResult Fail(ModelStateDictionary modelState)
        {
            var invalidProperties = modelState.Where(kv => kv.Value.Errors.Count > 0);
            var data = new Dictionary<string, string>();

            foreach(var invalidProperty in invalidProperties)
            {
                var message = string.Join(",", invalidProperty.Value.Errors.Select(e => e.ErrorMessage).ToArray());
                data.Add(invalidProperty.Key, message);
            }

            return new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new
                {
                    status = "fail",
                    data = data
                }
            };
        }
开发者ID:ivankustera,项目名称:AtomiaStore,代码行数:25,代码来源:JsonEnvelope.cs

示例9: ApiHttpError

        public ApiHttpError(ModelStateDictionary modelStateDictionary)
        {
            Message = "Invalid request.";
            Errors = new List<Error>();

            foreach (var item in modelStateDictionary.Where(m => m.Value.Errors.Count > 0))
            {
                var itemErrors = new List<string>();
                foreach (var childItem in item.Value.Errors)
                {
                    if (!string.IsNullOrEmpty(childItem.ErrorMessage))
                        itemErrors.Add(childItem.ErrorMessage);
                    else if (childItem.Exception != null)
                    {
                        itemErrors.Add(childItem.Exception.Message);
                        if (childItem.Exception.InnerException != null)
                            itemErrors.Add(childItem.Exception.InnerException.Message);
                    }
                    else
                        itemErrors.Add("Invalid parameter.");
                }
                Errors.Add(new Error(item.Key, itemErrors));
            }
        }
开发者ID:leocosta,项目名称:TicketStore,代码行数:24,代码来源:ApiHttpError.cs

示例10: SerializeErrors

 protected virtual object SerializeErrors(ModelStateDictionary modelState)
 {
     return modelState.Where(entry => entry.Value.Errors.Any())
                      .ToDictionary(entry => entry.Key, entry => SerializeModelState(entry.Value));
 }
开发者ID:akhuang,项目名称:Asp.net-MVC-3,代码行数:5,代码来源:GridActionAttribute.cs

示例11: ModelStateErrors

        public static void ModelStateErrors(ModelStateDictionary modelState)
        {
            var errors = modelState.Where(a => a.Value.Errors.Count > 0)
                .Select(b => new { b.Key, b.Value.Errors })
                .ToArray();

            foreach (var modelStateErrors in errors)
            {
                System.Diagnostics.Debug.WriteLine("...Errored When Binding.", modelStateErrors.Key.ToString());

            }

        }
开发者ID:yuqiqian,项目名称:Copacescc,代码行数:13,代码来源:SegmentsController.cs

示例12: ModelStateErrors

 public static ErrorInfo[] ModelStateErrors(ModelStateDictionary modelState)
 {
     return modelState.Where(x => x.Value.Errors.Count > 0)
     .Select(x => new ErrorInfo { Key = x.Key, Errors = x.Value.Errors })
     .ToArray();
 }
开发者ID:nhtera,项目名称:CrowdCMS,代码行数:6,代码来源:ErrorInfo.cs


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