4
Vote

RequiredIf throws an exception

description

I have DropDownFor which is being used as Dependency property and a TextBoxFor which is being validated
Here is the fragment of my View
<div class="editor-label"> @Html.LabelFor(model => model.PersonMaritalStatus) </div> <div class="editor-field"> @Html.DropDownListFor(model=>model.PersonMaritalStatus, new SelectList(ViewBag.MaritalStat, "Key", "Value",0)) @Html.ValidationMessageFor(model => model.PersonMaritalStatus) </div> <div class="editor-label"> @Html.LabelFor(model => model.SpouseName) </div> <div class="editor-field"> @Html.TextBoxFor(model => model.SpouseName, new { id="SpouseName"}) @Html.ValidationMessageFor(model => model.SpouseName) </div> And here is the part of my Model:
    [RequiredIf("PersonMaritalStatus",Operator.EqualTo,"2",ErrorMessage="Spouse name Required")]
    public string SpouseName { get; set; }
On the client side everything working as expected, but on server side diring validation, I'm getting
System.Data.Entity.Validation.DbUnexpectedValidationException was unhandled by user code
Message=An unexpected exception was thrown during validation of 'SpouseName' when invoking Foolproof.RequiredIfAttribute.IsValid. See the inner exception for details.
Source=EntityFramework
StackTrace:
   at System.Data.Entity.Internal.Validation.ValidationAttributeValidator.Validate(EntityValidationContext entityValidationContext, InternalMemberEntry property)
   at System.Data.Entity.Internal.Validation.PropertyValidator.Validate(EntityValidationContext entityValidationContext, InternalMemberEntry property)
   at System.Data.Entity.Internal.Validation.EntityValidator.ValidateProperties(EntityValidationContext entityValidationContext, InternalPropertyEntry parentProperty, List`1 validationErrors)
   at System.Data.Entity.Internal.Validation.TypeValidator.Validate(EntityValidationContext entityValidationContext, InternalPropertyEntry property)
   at System.Data.Entity.Internal.Validation.EntityValidator.Validate(EntityValidationContext entityValidationContext)
   at System.Data.Entity.Internal.InternalEntityEntry.GetValidationResult(IDictionary`2 items)
   at System.Data.Entity.DbContext.ValidateEntity(DbEntityEntry entityEntry, IDictionary`2 items)
   at System.Data.Entity.DbContext.GetValidationErrors()
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
   at AdultDayCare.Controllers.PatientController.Create(Patient p, FormCollection f) in C:\Users\Yuri\Documents\Visual Studio 2010\Projects\AdultDayCare\AdultDayCare\Controllers\PatientController.cs:line 111
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
InnerException: System.NotImplementedException
   Message=The method or operation is not implemented.
   Source=MVC Foolproof Validation
   StackTrace:
        at Foolproof.ModelAwareValidationAttribute.IsValid(Object value)
        at System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value, ValidationContext validationContext)
        at System.ComponentModel.DataAnnotations.ValidationAttribute.GetValidationResult(Object value, ValidationContext validationContext)
        at System.Data.Entity.Internal.Validation.ValidationAttributeValidator.Validate(EntityValidationContext entityValidationContext, InternalMemberEntry property)
   InnerException: 
Can anyone please help? These attributes are making developers life so much easier
Ready to donate to support development.

comments