Making exceptions for ValidationAttribute

So I have made a custom validation attribute for a property in my C# MVC view model, and it works as expected on the server side. But now I want the user to be able to cancel the validation by selecting a checkbox that says; skip verification, and then let the whole system store the value in the property anyway. But only for that specific selected property, all other properties should be validated as normal.

Any good suggestions and examples on how to do this?
LVL 2
itniflAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

itniflAuthor Commented:
Fixed it myself, did it like this:
public class VerifyADConnectionStringAttribute : ValidationAttribute
   {
      protected override ValidationResult IsValid(object value, ValidationContext validationContext) {
         string errorMessage;
         bool skipValidation = false;
         var WebPageConfigurationModel = validationContext.ObjectInstance as Models.View.WebPageConfiguration;
         if (WebPageConfigurationModel != null) {
            skipValidation = WebPageConfigurationModel.ADConnectionStringExemption;
         }
         if (!skipValidation) {
//Validate here, return whatever result.
}
//return success here if we get this far.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
itniflAuthor Commented:
Solved
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.