title: Conditional Validation in asp.net MVC4
body: <p>I want to be able to kick off some validation functions based upon what controller a view is called from... I will set a variable in ViewState or something and that will help me to know what controller this view was called from.  </p>
  
  <p>In other words, I want the validation to be required if a certain variable is set...  Here is how I use to do in MVC2 when I just put Jquery into my code...</p>
  
  <pre><code>HospitalFinNumber: {
                      required: function (element) {
                          debugger;
                          return '@isFlagSet' != 'True'; 
                      },
                      minlength: 6,
                      remote: function () {
                          //debugger;
                          return {
                              url: '@Url.Action("ValidateHosFin", "EditEncounter")',
                              data: { hospitalFin: $('#HospitalFinNumber').val(), encflag: '@encflag' }
                          };
                      }
                  }
  </code></pre>
  
  <p>You see what I am doing there.  This validation would only be required if a certain variable is set... In this case, the variable isFlagSet...  I would then set min Length and call a remote function to ensure that the value is unique.  </p>
  
  <p>I don't want to do this in all cases.</p>
  
  <p>From all I have read so far, there is no clear way to accomplish this using unobrtusive ajax?  Am I wrong, is there a way you can do this?  If not, how can I just place regular old jquery validation into my code?</p>