title: Custom Validation on Multiple Inputs in ASP.net MVC
body: <p>After researching various methods to implement custom form validation rules in MVC I have found, what I originally considered to be a straightforward bit of validation, to be rather more complex that I anticipated.</p>
  
  <p>I have 2 text inputs, one or the other (or both) need to be populated. If both are <code>NullOrEmpty</code> we need to throw an error.</p>
  
  <p>I have found <code>DataAnnotations</code> to have it's limitations when attempting to validate on multiple fields, giving me highlighting on both inputs and throwing a single error. Is this some beginners naivity? </p>
  
  <p>I also played around with <code>FluentValidation</code> and was unable to get the results I was after.</p>
  
  <p>Currently I am throwing the error in the Controller using:</p>
  
  <pre><code>ModelState.AddModelError("PropertyName", "You need to enter a Property Number or a Property Name")
  ModelState.AddModelError("PropertyNumber", String.Empty)
  </code></pre>
  
  <p>This gives me highlighting on both fields and server-side validation. I am now finding it difficult binding custom client-side validation without using DataAnnotations.</p>
  
  <p>Does anyone have any advice on how to do this properly? Any help or suggestions would be greatly appreciated. I need validation on the server/client, on both fields, with highlighting and a single error message.</p>
  
  <p>Thanks in advance.</p>