title: validating textboxes based on the URL entered
body: <p>I am trying to validate two textboxes based on the URL that has been entered, the textboxes are for job title and military rank.</p>
  
  <p>Generally for most of the routes I have created the job title textbox will be required only three URLs currently require military rank instead, in similar projects I have added a RequiredIf annotation using MVC Foolproof Validation which has been added to a view model, in the case I have tried using the annotation but because I am validating from a domain model project the Foolproof Validation is not working.</p>
  
  <p>I have currently partially implemented custom validation in the domain model as a handler class using this code:</p>
  
  <pre><code> if (paymentDetailsForm.UseRankInsteadOfJobTitle)
          {
              if (paymentDetailsForm.Rank == null)
              {
                  yield return new ValidationResult(Resources.JobRankRequired);
              }
          }
  </code></pre>
  
  <p>essentially I have created a Boolean value called UseRankInsteadOfJobTitle which is set to either true or false depending on the URL entered.</p>
  
  <p>to set this value as either true or false I have used this code in the controller:</p>
  
  <pre><code>if ((programme.Code == "AMAC") || (programme.Code == "AMACD") || (programme.Code == "AMACR"))
          {
              ViewData["UseRankInsteadOfJobTitle"] = true;
          }
          else
          {
              ViewData["UseRankInsteadOfJobTitle"] = false;
          }
  </code></pre>
  
  <p>And then created a hidden field on the view:</p>
  
  <pre><code>@Html.Hidden("UseRankInsteadOfJobTitle", @ViewData["UseRankInsteadOfJobTitle"])
  </code></pre>
  
  <p>the following HTML is then generated:</p>
  
  <p><strong>for false values</strong></p>
  
  <pre><code>&lt;input data-val="true" data-val-required="The Boolean field is required." id="UseRankInsteadOfJobTitle" name="UseRankInsteadOfJobTitle" type="hidden" value="False" /&gt;
  </code></pre>
  
  <p><strong>for true values</strong></p>
  
  <pre><code>&lt;input data-val="true" data-val-required="The Boolean field is required." id="UseRankInsteadOfJobTitle" name="UseRankInsteadOfJobTitle" type="hidden" value="True" /&gt; 
  </code></pre>
  
  <p>Currently the validation message is not being displayed for either job title or military rank, I need a way of ascertaining whether the value of USERankInsteadOfJobTitle is true or false.</p>
  
  <p>I have tried using the formCollection class to get the value of the hidden field but so far this has not worked.</p>
  
  <p>Any advice on how I could do this or better way of validating these textboxes would be appreciated.</p>