本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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());
}
}
示例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
};
}
示例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;
}
示例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;
}
示例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
}
};
}
示例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));
}
}
示例10: SerializeErrors
protected virtual object SerializeErrors(ModelStateDictionary modelState)
{
return modelState.Where(entry => entry.Value.Errors.Any())
.ToDictionary(entry => entry.Key, entry => SerializeModelState(entry.Value));
}
示例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());
}
}
示例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();
}