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


C# ModelState类代码示例

本文整理汇总了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;
 }
开发者ID:timcdlucas,项目名称:Refactored-Madingley,代码行数:12,代码来源:RunState.cs

示例2: ReadConfigReturn

        public static void ReadConfigReturn(TreeMgmtServerConfig c)
        {
            Condition.IsTrue(State == ModelState.Uninitialized);

            Config = c;
            State = ModelState.Initialized;
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:7,代码来源:TreeMgmtModel.cs

示例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;
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:32,代码来源:ResilientHandleModel.cs

示例4: UpdateState

 protected void UpdateState(ModelState state, string message)
 {
     if (ModelStateUpdated != null)
     {
         ModelStateUpdated(this, new ModelStateEventArgs(state, message));
     }
 }
开发者ID:sunnnjin,项目名称:Blackbox,代码行数:7,代码来源:ViewModelBase.cs

示例5: ErrorsProperty

        public void ErrorsProperty()
        {
            // Arrange
            ModelState modelState = new ModelState();

            // Act & Assert
            Assert.NotNull(modelState.Errors);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:8,代码来源:ModelStateTest.cs

示例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);
        }
开发者ID:sanyaade-mobiledev,项目名称:ASP.NET-Mvc-2,代码行数:11,代码来源:ValidationExtensions.cs

示例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);
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:12,代码来源:ValidateNegotiateInfoModel.cs

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

示例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));
      //}
    }
开发者ID:pillesoft,项目名称:JolTudomE,代码行数:14,代码来源:BaseModel.cs

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

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

示例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());
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:22,代码来源:ValueExtensionsTest.cs

示例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;
    }
开发者ID:davpanko,项目名称:azure-active-directory-expense-app,代码行数:23,代码来源:MoneyModelBinder.cs

示例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());
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:27,代码来源:SelectExtensionsTest.cs

示例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("&lt;{ foo = ViewItemFoo &lt;&quot;>, bar = (null) }", helper.ValueForModel("<{0}").ToHtmlString());
            Assert.Equal("&lt;ViewDataFoo &lt;&quot;>", helper.Value("foo", "<{0}").ToHtmlString());
            Assert.Equal("&lt;ViewItemFoo &lt;&quot;>", helper.ValueFor(m => m.foo, "<{0}").ToHtmlString());
            Assert.Equal("AttemptedValueBar &lt;&quot;>", helper.ValueFor(m => m.bar).ToHtmlString());
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:18,代码来源:ValueExtensionsTest.cs


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