本文整理汇总了C#中ModelState类的典型用法代码示例。如果您正苦于以下问题:C# ModelState类的具体用法?C# ModelState怎么用?C# ModelState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModelState类属于命名空间,在下文中一共展示了ModelState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunState
/// <summary>
/// RunState constructor.
/// </summary>
/// <param name="modelState">Model state.</param>
/// <param name="output">Output implementation.</param>
public RunState(
ModelState modelState,
IOutput output)
{
this.ModelState = modelState;
this.Output = output;
}
示例2: ReadConfigReturn
public static void ReadConfigReturn(TreeMgmtServerConfig c)
{
Condition.IsTrue(State == ModelState.Uninitialized);
Config = c;
State = ModelState.Initialized;
}
示例3: Disconnect
public static void Disconnect()
{
Condition.IsTrue(State == ModelState.Connected);
Condition.IsNull(Request);
Condition.IsNotNull(Open);
ModelHelper.Log(LogType.Requirement, "3.3.7.1 Handling Loss of a Connection");
if (Config.IsLeasingSupported && Open.IsResilient)
{
ModelHelper.Log(LogType.Requirement,
"If any of the following conditions is satisfied, it indicates that the Open is to be preserved for reconnect. ");
ModelHelper.Log(LogType.Requirement, "\tThe server supports leasing and Open.IsResilient is TRUE.");
ModelHelper.Log(LogType.TestInfo, "The above conditions are met.");
ModelHelper.Log(LogType.TestInfo, "The Open is preserved.");
}
else if (Open.IsDurable)
{
ModelHelper.Log(LogType.Requirement,
"If any of the following conditions is satisfied, it indicates that the Open is to be preserved for reconnect. ");
ModelHelper.Log(LogType.Requirement, "\tOpen.OplockLevel is equal to SMB2_OPLOCK_LEVEL_BATCH and Open.OplockState is equal to Held, and Open.IsDurable is TRUE.");
ModelHelper.Log(LogType.TestInfo, "The above conditions are met.");
ModelHelper.Log(LogType.TestInfo, "The Open is preserved.");
}
else
{
ModelHelper.Log(LogType.Requirement, "If the Open is not to be preserved for reconnect, the server MUST close the Open as specified in section 3.3.4.17.");
ModelHelper.Log(LogType.TestInfo, "The Open is closed.");
Open = null;
}
State = ModelState.Disconnected;
}
示例4: UpdateState
protected void UpdateState(ModelState state, string message)
{
if (ModelStateUpdated != null)
{
ModelStateUpdated(this, new ModelStateEventArgs(state, message));
}
}
示例5: ErrorsProperty
public void ErrorsProperty()
{
// Arrange
ModelState modelState = new ModelState();
// Act & Assert
Assert.NotNull(modelState.Errors);
}
示例6: GetUserErrorMessageOrDefault
private static string GetUserErrorMessageOrDefault(HttpContextBase httpContext, ModelError error, ModelState modelState) {
if (!String.IsNullOrEmpty(error.ErrorMessage)) {
return error.ErrorMessage;
}
if (modelState == null) {
return null;
}
string attemptedValue = (modelState.Value != null) ? modelState.Value.AttemptedValue : null;
return String.Format(CultureInfo.CurrentCulture, GetInvalidPropertyValueResource(httpContext), attemptedValue);
}
示例7: ReadConfigReturn
public static void ReadConfigReturn(ValidateNegotiateInfoConfig c)
{
Condition.IsTrue(State == ModelState.Uninitialized);
Condition.IsNotNull(c);
Config = c;
State = ModelState.Initialized;
Condition.IsTrue(Config.ValidateNegotiateInfoSupported ==
ValidateNegotiateInfoInServer.NotSupportValidateNegotiateInfo ||
Config.ValidateNegotiateInfoSupported ==
ValidateNegotiateInfoInServer.SupportValidateNegotiateInfo);
}
示例8: GetTextAreaViewDataWithErrors
private static ViewDataDictionary GetTextAreaViewDataWithErrors() {
ViewDataDictionary viewData = new ViewDataDictionary { { "foo", "ViewDataFoo" } };
viewData.Model = new { foo = "ViewItemFoo", bar = "ViewItemBar" };
ModelState modelStateFoo = new ModelState();
modelStateFoo.Errors.Add(new ModelError("foo error 1"));
modelStateFoo.Errors.Add(new ModelError("foo error 2"));
viewData.ModelState["foo"] = modelStateFoo;
modelStateFoo.Value = HtmlHelperTest.GetValueProviderResult(new string[] { "AttemptedValueFoo" }, "AttemptedValueFoo");
return viewData;
}
示例9: OnPropertyChanged
public override void OnPropertyChanged(string propname)
{
if (_ModelState != Model.ModelState.New)
{
ModelState = Model.ModelState.Modified;
}
base.OnPropertyChanged(propname);
//if (PropertyChanged != null)
//{
// PropertyChanged(this, new PropertyChangedEventArgs(propname));
//}
}
示例10: Equal
public static bool Equal( ModelState a, ModelState b )
{
if ( System.Object.ReferenceEquals( a, b ) ) return true;
if ( ( (object)a == null ) || ( (object)b == null ) ) return false;
if ( a.ducked != b.ducked ) return false;
if ( a.jumped != b.jumped ) return false;
if ( a.onground != b.onground ) return false;
if ( a.sleeping != b.sleeping ) return false;
if ( a.waterLevel != b.waterLevel ) return false;
if ( a.flinchLocation != b.flinchLocation ) return false;
return true;
}
示例11: BindModel
public object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext)
{
ValueProviderResult valueResult = bindingContext.ValueProvider
.GetValue(bindingContext.ModelName);
ModelState modelState = new ModelState { Value = valueResult };
object actualValue = null;
try
{
actualValue = Convert.ToDecimal(valueResult.AttemptedValue,
CultureInfo.CurrentCulture);
}
catch (FormatException e)
{
modelState.Errors.Add(e);
}
bindingContext.ModelState.Add(bindingContext.ModelName, modelState);
return actualValue;
}
示例12: ValueHelpersWithErrorsGetValueFromModelState
public void ValueHelpersWithErrorsGetValueFromModelState()
{
// Arrange
ViewDataDictionary<FooBarModel> viewDataWithErrors = new ViewDataDictionary<FooBarModel> { { "foo", "ViewDataFoo" } };
viewDataWithErrors.Model = new FooBarModel() { foo = "ViewItemFoo", bar = "ViewItemBar" };
viewDataWithErrors.TemplateInfo.HtmlFieldPrefix = "FieldPrefix";
ModelState modelStateFoo = new ModelState();
modelStateFoo.Value = HtmlHelperTest.GetValueProviderResult(new string[] { "AttemptedValueFoo" }, "AttemptedValueFoo");
viewDataWithErrors.ModelState["FieldPrefix.foo"] = modelStateFoo;
ModelState modelStateFooBar = new ModelState();
modelStateFooBar.Value = HtmlHelperTest.GetValueProviderResult(new string[] { "AttemptedValueFooBar" }, "AttemptedValueFooBar");
viewDataWithErrors.ModelState["FieldPrefix"] = modelStateFooBar;
HtmlHelper<FooBarModel> helper = MvcHelper.GetHtmlHelper(viewDataWithErrors);
// Act & Assert
Assert.Equal("AttemptedValueFoo", helper.Value("foo").ToHtmlString());
Assert.Equal("AttemptedValueFoo", helper.ValueFor(m => m.foo).ToHtmlString());
Assert.Equal("AttemptedValueFooBar", helper.ValueForModel().ToHtmlString());
}
示例13: BindModel
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
var modelState = new ModelState { Value = valueResult };
decimal actualValue = 0;
try
{
if (bindingContext.ModelMetadata.DataTypeName == DataType.Currency.ToString())
decimal.TryParse(valueResult.AttemptedValue, NumberStyles.Currency, null, out actualValue);
else
actualValue = Convert.ToDecimal(valueResult.AttemptedValue, CultureInfo.CurrentCulture);
}
catch (FormatException e)
{
modelState.Errors.Add(e);
}
bindingContext.ModelState.Add(bindingContext.ModelName, modelState);
return actualValue;
}
示例14: EnumDropDownListForWithErrorsAndValue
public void EnumDropDownListForWithErrorsAndValue()
{
// Arrange
ViewDataDictionary<EnumModel> viewData = new ViewDataDictionary<EnumModel>(_enumDropDownListViewData);
ModelState modelState = new ModelState
{
Errors = { new ModelError("WithDisplay error 1"), new ModelError("WithDisplay error 2"), },
Value = new ValueProviderResult(new string[] { "1", }, "1", null),
};
viewData.ModelState["WithDisplay"] = modelState;
HtmlHelper<EnumModel> helper = MvcHelper.GetHtmlHelper(viewData);
// Act
MvcHtmlString html = helper.EnumDropDownListFor(m => m.WithDisplay,
htmlAttributes: HtmlHelperTest.AttributesObjectDictionary);
// Assert
Assert.Equal(
"<select baz=\"BazObjValue\" class=\"input-validation-error\" id=\"WithDisplay\" name=\"WithDisplay\">" +
"<option value=\"0\">First</option>" + Environment.NewLine +
"<option selected=\"selected\" value=\"1\">Second</option>" + Environment.NewLine +
"<option value=\"2\">Third</option>" + Environment.NewLine +
"<option value=\"3\">Fourth</option>" + Environment.NewLine +
"</select>",
html.ToHtmlString());
}
示例15: ValueHelpersEncodeValue
public void ValueHelpersEncodeValue()
{
// Arrange
ViewDataDictionary<FooBarModel> viewData = new ViewDataDictionary<FooBarModel> { { "foo", @"ViewDataFoo <"">" } };
viewData.Model = new FooBarModel { foo = @"ViewItemFoo <"">" };
ModelState modelStateFoo = new ModelState();
modelStateFoo.Value = HtmlHelperTest.GetValueProviderResult(new string[] { @"AttemptedValueBar <"">" }, @"AttemptedValueBar <"">");
viewData.ModelState["bar"] = modelStateFoo;
HtmlHelper<FooBarModel> helper = MvcHelper.GetHtmlHelper(viewData);
// Act & Assert
Assert.Equal("<{ foo = ViewItemFoo <">, bar = (null) }", helper.ValueForModel("<{0}").ToHtmlString());
Assert.Equal("<ViewDataFoo <">", helper.Value("foo", "<{0}").ToHtmlString());
Assert.Equal("<ViewItemFoo <">", helper.ValueFor(m => m.foo, "<{0}").ToHtmlString());
Assert.Equal("AttemptedValueBar <">", helper.ValueFor(m => m.bar).ToHtmlString());
}