• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ModelState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ModelState的典型用法代码示例。如果您正苦于以下问题:C# ModelState类的具体用法?C# ModelState怎么用?C# ModelState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ModelState类属于命名空间,在下文中一共展示了ModelState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: GetRadioButtonViewData

        // RADIO
        private static ViewDataDictionary GetRadioButtonViewData() {
            ViewDataDictionary viewData = new ViewDataDictionary { { "foo", "ViewDataFoo" } };
            viewData.Model = new { foo = "ViewItemFoo", bar = "ViewItemBar" };
            ModelState modelState = new ModelState();
            modelState.Value = HtmlHelperTest.GetValueProviderResult("ViewDataFoo", "ViewDataFoo");
            viewData.ModelState["foo"] = modelState;

            return viewData;
        }
开发者ID:ledgarl,项目名称:Samples,代码行数:10,代码来源:InputExtensionsTest.cs


示例17: GetHiddenViewDataWithErrors

        private static ViewDataDictionary GetHiddenViewDataWithErrors() {
            ViewDataDictionary viewData = new ViewDataDictionary { { "foo", "ViewDataFoo" } };
            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("AttemptedValueFoo", "AttemptedValueFoo");

            return viewData;
        }
开发者ID:ledgarl,项目名称:Samples,代码行数:10,代码来源:InputExtensionsTest.cs


示例18: SetupConnection

        public static void SetupConnection(ModelDialectRevision clientMaxDialect)
        {
            Condition.IsTrue(state == ModelState.Initialized);
            Condition.IsNull(request);

            negotiateDialect = ModelHelper.DetermineNegotiateDialect(clientMaxDialect, config.MaxSmbVersionSupported);

            if ((negotiateDialect == DialectRevision.Smb21 || ModelUtility.IsSmb3xFamily(negotiateDialect))
                && config.IsMultiCreditSupportedOnServer)
            {
                ModelHelper.Log(
                    LogType.Requirement,
                    "3.3.5.4: If the common dialect is SMB 2.1 or 3.x dialect family and the underlying connection is either TCP port 445 or RDMA," +
                    "Connection.SupportsMultiCredit MUST be set to TRUE; otherwise, it MUST be set to FALSE.");
                ModelHelper.Log(
                    LogType.TestInfo,
                    "Common dialect is {0} and server implementation {1} multicredit", negotiateDialect,
                    config.IsMultiCreditSupportedOnServer ? "supports" : "does not support");

                isMultiCreditSupported = true;

                ModelHelper.Log(
                    LogType.TestInfo,
                    "Connection.SupportsMultiCredit is set to TRUE");
            }
            else
            {
                isMultiCreditSupported = false;

                ModelHelper.Log(
                    LogType.TestInfo,
                    "Connection.SupportsMultiCredit is set to FALSE");
            }

            state = ModelState.Connected;
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:36,代码来源:CreditMgmtModel.cs


示例19: IsValidPropertyReturnsFalseIfErrors

        public void IsValidPropertyReturnsFalseIfErrors()
        {
            // Arrange
            ModelState errorState = new ModelState() { Value = HtmlHelperTest.GetValueProviderResult("quux", "quux") };
            errorState.Errors.Add("some error");
            ModelStateDictionary dictionary = new ModelStateDictionary()
            {
                { "foo", new ModelState() { Value = HtmlHelperTest.GetValueProviderResult("bar", "bar") } },
                { "baz", errorState }
            };

            // Act
            bool isValid = dictionary.IsValid;

            // Assert
            Assert.False(isValid);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:17,代码来源:ModelStateDictionaryTest.cs


示例20: ExpectDisconnect

        public static void ExpectDisconnect()
        {
            Condition.IsTrue(state == ModelState.Connected);
            Condition.IsTrue(expectDisconnection);

            state = ModelState.Disconnected;
            acceptingCondition = true;
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:8,代码来源:CreditMgmtModel.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ModelStateDictionary类代码示例发布时间:2022-05-24
下一篇:
C# ModelRoot类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap