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


C# ModelStateDictionary.Remove方法代码示例

本文整理汇总了C#中ModelStateDictionary.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.Remove方法的具体用法?C# ModelStateDictionary.Remove怎么用?C# ModelStateDictionary.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelStateDictionary的用法示例。


在下文中一共展示了ModelStateDictionary.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CleanModelState

        public virtual void CleanModelState(ModelStateDictionary modelState)
        {
            modelState.Remove("ValidationSummary");
            modelState.Remove("ActionPerformed");

            ValidationSummary = ValidationSummary ?? new ValidationSummaryEditorViewModel();
        }
开发者ID:IkeCode-SmartSolutions,项目名称:Clinike,代码行数:7,代码来源:BaseViewModel.cs

示例2: ValidationHackRemoveNameAndBlankKey

        /// <summary>
        /// Validations the hack remove name and blank key.
        /// </summary>
        public static void ValidationHackRemoveNameAndBlankKey(ModelStateDictionary modelStateDictionary)
        {
            ModelState modelState = modelStateDictionary[string.Empty];

            if (modelState != null)
            {
                //Setting the new error with an name. Removeing the old one which doesn't have a name.
                modelStateDictionary.AddModelError("PasswordDontMatch", modelState.Errors[0].ErrorMessage);
                modelStateDictionary.Remove(string.Empty);
            }
        }
开发者ID:chuckconway,项目名称:the-memorable-moments,代码行数:14,代码来源:ValidationHelper.cs

示例3: ValidateBusiness

 /// <summary>
 /// Removes model state errors for individual required fields
 /// </summary>
 /// <param name="ModelState"></param>
 void ValidateBusiness(ModelStateDictionary ModelState)
 {
     ModelState.Remove("FirstName");
     ModelState.Remove("LastName");
 }
开发者ID:nathantownsend,项目名称:myCoal,代码行数:9,代码来源:ContactVM.cs

示例4: ValidateIndividual

 /// <summary>
 /// Removes model state errors for business required fields
 /// </summary>
 /// <param name="ModelState"></param>
 void ValidateIndividual(ModelStateDictionary ModelState)
 {
     ModelState.Remove("CompanyName");
     ModelState.Remove("TaxID");
 }
开发者ID:nathantownsend,项目名称:myCoal,代码行数:9,代码来源:ContactVM.cs

示例5: ValidateAddress1

 /// <summary>
 /// Ensures the address 1 block was filled out properly
 /// </summary>
 /// <param name="ModelState"></param>
 void ValidateAddress1(ModelStateDictionary ModelState)
 {
     // either address 1 or PoBox satisfy the requirement that at least one is entered
     if (ModelState["Address11"].Errors.Count == 0 || ModelState["POBox1"].Errors.Count == 0)
     {
         ModelState.Remove("POBox1");
         ModelState.Remove("Address11");
     }
 }
开发者ID:nathantownsend,项目名称:myCoal,代码行数:13,代码来源:ContactVM.cs

示例6: ValidateAddress2

        /// <summary>
        /// Validates the second address block 
        /// </summary>
        /// <param name="ModelState"></param>
        void ValidateAddress2(ModelStateDictionary ModelState)
        {
            string[] testing = new string[] { Address21, Address22, POBox2, City2, StateID2, ZipCode2 };
            bool validate = false;

            // if any field in address 2 contains data then validate the address, otherwise skip it
            foreach(string test in testing)
            {
                if (!string.IsNullOrEmpty(test))
                    validate = true;
            }

            // if no data in address 2 block then skip validation
            if (!validate)
            {
                ModelState.Remove("Address21");
                ModelState.Remove("Address22");
                ModelState.Remove("POBox2");
                ModelState.Remove("City2");
                ModelState.Remove("StateID2");
                ModelState.Remove("ZipCode2");
                return;
            }

            // either address 1 or PoBox satisfy the requirement that at least one is entered
            if (ModelState["Address21"].Errors.Count == 0 || ModelState["POBox2"].Errors.Count == 0)
            {
                ModelState.Remove("POBox2");
                ModelState.Remove("Address21");
            }
        }
开发者ID:nathantownsend,项目名称:myCoal,代码行数:35,代码来源:ContactVM.cs

示例7: SetLogo

        private void SetLogo(EditEventViewModel viewModel, ModelStateDictionary modelState)
        {
            bool hasLogo = Session[CurrentLogoKey] != null;

            if(hasLogo)
            {
                viewModel.Logo = (byte[])Session[CurrentLogoKey];
                viewModel.IsLogoSetted = true;
                viewModel.HasLogo = true;
                if(modelState.ContainsKey("HasLogo"))
                    modelState.Remove("HasLogo");
            }
        }
开发者ID:garymedina,项目名称:MyEvents,代码行数:13,代码来源:EventController.cs

示例8: ValidateAdditionalInformation

        /// <summary>
        /// Validate the additional info block
        /// </summary>
        /// <param name="ModelState"></param>
        void ValidateAdditionalInformation(ModelStateDictionary ModelState)
        {
            if (!ShowAdditionalInfo)
            {
                ModelState.Remove("LegalEntityID");
                ModelState.Remove("LegalStructureDescription");
                ModelState.Remove("DateOfIncorporation");
                ModelState.Remove("StateOfIncorporationID");
                ModelState.Remove("ResponsibleParty");
                return;
            }

            // Applicant / Individual only shows Responsible Party
            if (ContactTypeID == "Applicant" && !IsBusiness)
            {
                ModelState.Remove("LegalEntityID");
                ModelState.Remove("LegalStructureDescription");
                ModelState.Remove("DateOfIncorporation");
                ModelState.Remove("StateOfIncorporationID");
            }

            // Applicant / Business shows everything
            if (ContactTypeID == "Applicant" && IsBusiness)
            {
                if (LegalEntityID != "Other")
                    ModelState.Remove("LegalStructureDescription");

                if (!ShowIncorporationDetails)
                {
                    ModelState.Remove("DateOfIncorporation");
                    ModelState.Remove("StateOfIncorporationID");
                }
            }

            // Resident Agent / Business
            if (ContactTypeID == "Resident Agent" && IsBusiness)
            {
                // responsible party doesn't show here
                ModelState.Remove("ResponsibleParty");

                if (LegalEntityID != "Other")
                    ModelState.Remove("LegalStructureDescription");

                if (!ShowIncorporationDetails)
                {
                    ModelState.Remove("DateOfIncorporation");
                    ModelState.Remove("StateOfIncorporationID");
                }
            }
        }
开发者ID:nathantownsend,项目名称:myCoal,代码行数:54,代码来源:ContactVM.cs

示例9: Remove_ForNotModelsExpression_RemovesModelStateKey

        public void Remove_ForNotModelsExpression_RemovesModelStateKey()
        {
            // Arrange
            var variable = "Test";
            var dictionary = new ModelStateDictionary();
            dictionary.Add("variable", new ModelStateEntry());

            // Act
            dictionary.Remove<TestModel>(model => variable);

            // Assert
            Assert.Empty(dictionary);
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:13,代码来源:ModelStateDictionaryExtensionsTest.cs

示例10: UpdateConsignorStatementForm

        //UpdateConsignorStatementForm
        public object UpdateConsignorStatementForm(string cons, ModelStateDictionary ModelState)
        {
            long co_id = 0;
            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                ConsignorStatementForm c = serializer.Deserialize<ConsignorStatementForm>(cons);

                c.Validate(ModelState);

                if (ModelState.IsValid)
                {
                    if ((co_id = GetConsignmentStatement(c.User_ID, c.Event_ID)) > 0 && c.ID == 0)
                        return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The consignor statement for this seller and this event already exists (Cons#" + co_id.ToString() + ")");

                    if (!UpdateConsignorStatement(c))
                        return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The user's information wasn't saved.");
                    co_id = c.ID;
                }
                else
                {
                    ModelState.Remove("cons");
                    var errors = (from M in ModelState select new { field = M.Key, message = M.Value.Errors.FirstOrDefault().ErrorMessage }).ToArray();
                    return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Please correct the errors and try again.", errors);
                }
            }
            catch (Exception ex)
            {
                return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message);
            }
            return new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS, "", co_id);
        }
开发者ID:clpereira2001,项目名称:Lelands-Master,代码行数:33,代码来源:AuctionRepository.cs

示例11: UpdateEventForm

        //UpdateEventForm
        public object UpdateEventForm(string evnt, ModelStateDictionary ModelState)
        {
            try
              {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            EventForm e = serializer.Deserialize<EventForm>(evnt);

            e.Validate(ModelState);

            if (e.DateEnd.CompareTo(DateTime.Now) <= 0 && AppHelper.CurrentUser.IsAdmin)
              return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't update this event.");

            if (ModelState.IsValid)
            {
              if (!UpdateEvent(e))
            return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The event's information wasn't saved.");
            }
            else
            {
              ModelState.Remove("evnt");
              var errors = (from M in ModelState select new { field = M.Key, message = M.Value.Errors.FirstOrDefault().ErrorMessage }).ToArray();
              return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Please correct the errors and try again.", errors);
            }
              }
              catch (Exception ex)
              {
            return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message);
              }
              return new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS);
        }
开发者ID:clpereira2001,项目名称:Lelands-Master,代码行数:31,代码来源:EventRepository.cs

示例12: Remove_ForRelationExpression_RemovesModelStateKey

        public void Remove_ForRelationExpression_RemovesModelStateKey()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.Add("Child.Text", new ModelStateEntry());

            // Act
            dictionary.Remove<TestModel>(model => model.Child.Text);

            // Assert
            Assert.Empty(dictionary);
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:12,代码来源:ModelStateDictionaryExtensionsTest.cs

示例13: KeysEnumerable_ReturnsAllKeys

        public void KeysEnumerable_ReturnsAllKeys()
        {
            // Arrange
            var expected = new[] { "Property1", "Property4", "Property1.Property2", "Property2[Property3]" };
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("Property1");
            dictionary.AddModelError("Property1.Property2", "Property2 invalid.");
            dictionary.AddModelError("Property2", "Property invalid.");
            dictionary.AddModelError("Property2[Property3]", "Property2[Property3] invalid.");
            dictionary.MarkFieldSkipped("Property4");
            dictionary.Remove("Property2");

            // Act
            var keys = dictionary.Keys;

            // Assert
            Assert.Equal(expected, keys);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:18,代码来源:ModelStateDictionaryTest.cs

示例14: GetEnumerable_ReturnsAllNonContainerNodes

        public void GetEnumerable_ReturnsAllNonContainerNodes()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("Property1");
            dictionary.SetModelValue("Property1.Property2", "value", "value");
            dictionary.AddModelError("Property2", "Property invalid.");
            dictionary.AddModelError("Property2[Property3]", "Property2[Property3] invalid.");
            dictionary.MarkFieldSkipped("Property4");
            dictionary.Remove("Property2");

            // Act & Assert
            Assert.Collection(
                dictionary,
                entry =>
                {
                    Assert.Equal("Property1", entry.Key);
                    Assert.Equal(ModelValidationState.Valid, entry.Value.ValidationState);
                    Assert.Null(entry.Value.RawValue);
                    Assert.Null(entry.Value.AttemptedValue);
                    Assert.Empty(entry.Value.Errors);
                },
                entry =>
                {
                    Assert.Equal("Property4", entry.Key);
                    Assert.Equal(ModelValidationState.Skipped, entry.Value.ValidationState);
                    Assert.Null(entry.Value.RawValue);
                    Assert.Null(entry.Value.AttemptedValue);
                    Assert.Empty(entry.Value.Errors);
                },
                entry =>
                {
                    Assert.Equal("Property1.Property2", entry.Key);
                    Assert.Equal(ModelValidationState.Unvalidated, entry.Value.ValidationState);
                    Assert.Equal("value", entry.Value.RawValue);
                    Assert.Equal("value", entry.Value.AttemptedValue);
                    Assert.Empty(entry.Value.Errors);
                },
                entry =>
                {
                    Assert.Equal("Property2[Property3]", entry.Key);
                    Assert.Equal(ModelValidationState.Invalid, entry.Value.ValidationState);
                    Assert.Null(entry.Value.RawValue);
                    Assert.Null(entry.Value.AttemptedValue);
                    Assert.Collection(entry.Value.Errors,
                        error => Assert.Equal("Property2[Property3] invalid.", error.ErrorMessage));
                });
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:48,代码来源:ModelStateDictionaryTest.cs

示例15: ContainsKey_ReturnsFalse_IfNodeHasBeenRemoved

        public void ContainsKey_ReturnsFalse_IfNodeHasBeenRemoved(string key)
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.AddModelError(key, "some error");

            // Act
            var remove = dictionary.Remove(key);
            var containsKey = dictionary.ContainsKey(key);

            // Assert
            Assert.True(remove);
            Assert.False(containsKey);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:14,代码来源:ModelStateDictionaryTest.cs


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