c# - How to make FluentValidation ignore a property -
i have following view model
public class myviewmodel { public myviewmodelclasswithvalidator mandatoryproperty {get; set;} public myviewmodelclasswithvalidator optionalproperty {get; set;} public class myviewmodelvalidator : abstractvalidator<myviewmodel> { public myviewmodelvalidator() { rulefor(x=> x.mandatoryproperty) //... //no rule property 2 } } }
i'm looking way make optionalproperty ignored fluentvalidation. here, validation errors of optional property still added modelstate.
this answer suggests either 1. avoid reusing child model, not option in case, , 2. delete errors modelstate. before writing dirty class modelstate httpcontext, i'd know if there's other way i'm unaware of since answer old.
my objective keep validation logic encapsulated in viewmodels.
thank you
okay i've found easy work around. i've created extension class threadstatic field holding reference current controller. controllers derive base controller, set current controller in constructor. once have controller have modelstate problem fixed.
Comments
Post a Comment