本文整理汇总了C#中ModelStateDictionary.Select方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.Select方法的具体用法?C# ModelStateDictionary.Select怎么用?C# ModelStateDictionary.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelStateDictionary
的用法示例。
在下文中一共展示了ModelStateDictionary.Select方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DictionnaryHasValueAndError
public static void DictionnaryHasValueAndError(ModelStateDictionary dict, string value, string error)
{
Assert.AreEqual(1, dict.Count);
var errors = dict.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList();
var values = dict.Select(x => x.Key).ToList();
foreach (var cur in values)
Assert.AreEqual(value, cur);
foreach (var cur in errors)
foreach (var cur2 in cur)
Assert.AreEqual(error, cur2.ErrorMessage);
}
示例2: SerialiseModelState
protected string SerialiseModelState(ModelStateDictionary modelState)
{
var entries = modelState
.Select(m => new ModelStateTransferEntry(m.Key, m.Value))
.ToList();
return JsonConvert.SerializeObject(entries, JsonSettings);
}
示例3: AddModelStateErrors
public void AddModelStateErrors(ModelStateDictionary modelState)
{
foreach (var modelStateErrors in modelState.Select(x => x.Value.Errors))
{
foreach (var error in modelStateErrors)
{
Errors.Add(error.ErrorMessage);
}
}
}
示例4: ModelStateValidationJsonResult
/// <summary>
/// Returns a JSON result that contains model errors.
/// </summary>
public ModelStateValidationJsonResult(ModelStateDictionary state)
{
Data = new
{
Errors = state.Select(model => new
{
model.Key,
Messages = model.Value.Errors.Select(e => e.ErrorMessage)
})
};
}
示例5: MvcFormValidationResult
/// <summary>
/// 创建 MvcFormValidationResult 对象
/// </summary>
/// <param name="form">所验证的表单</param>
/// <param name="modelStates">要包装的模型验证状态</param>
public MvcFormValidationResult( HtmlForm form, ModelStateDictionary modelStates )
{
if ( modelStates == null )
throw new ArgumentNullException( "modelState" );
Errors = new FormValidationErrorCollection();
Form = form;
modelStates.Select( CreateValidationError ).NotNull().ForAll( e => Errors.Add( e ) );
if ( Errors.Any() )
HasError = true;
}
示例6: PrepareErrMsg
private string PrepareErrMsg(ModelStateDictionary mdl) {
List<ModelErrorCollection> errors = mdl.Select(x => x.Value.Errors).ToList();
String msg = string.Empty;
foreach (ModelErrorCollection error in errors)
{
foreach (ModelError modelError in error)
{
msg += msg + modelError.ErrorMessage + " ";
}
}
return msg;
}