title: How to Determine in Overridden IsValid Function of ValidationAttribute If It's Save or Submit Event
body: <p>I have extended the System.ComponentModel.DataAnnotations.ValidationAttribute class and overridden two of its IsValid(...) functions below.</p>
  <pre><code>using System;
  using System.ComponentModel.DataAnnotations;
  
  namespace FMT.Domain.Utilities
  {
      [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
      sealed public class RequiredOnSubmit : ValidationAttribute
      {
          public override bool IsValid(object value)
          {
              if (/* how to determine if this is a &quot;save&quot; or &quot;submit&quot; event? */)
                  return true;
  
              bool validOrNot = base.IsValid(value);
              return validOrNot;
          }
  
          protected override ValidationResult IsValid(object value, ValidationContext validationContext)
          {
              if (/* how to determine if this is a &quot;save&quot; or &quot;submit&quot; event? */)
                  return null; // or a ValidationResult object that says validation passed.
              
              ValidationResult myValidationResult = base.IsValid(value, validationContext);
              return myValidationResult;
          }
      }
  }
  </code></pre>
  <p>A .cshtml page contains an input field for the following property:</p>
  <pre><code>public class NonLeaseFundingRequest
  {
          ...
          [MaxLength(150)]
          [RequiredOnSubmit(ErrorMessage = &quot;LineOfBusiness required&quot;)]
          public string LineOfBusiness { get; set; }
  }
  </code></pre>
  <p>When I click a &quot;save&quot; button on that .cshtml page, both those functions above get invoked.  My goal is to basically always return true (skip validation) in the event of a &quot;save&quot; but not &quot;submit&quot;.  How can I determine in either of those two functions, that it was called upon a &quot;save&quot; and not a &quot;submit&quot; button click event?</p>