title: ASP.NET MVC: Implement client side validation with attribute without IClientValidatable
body: <p>How can I create a custom validation attribute with client side validation without implementing <code>IClientValidatable</code>?</p>
  
  <p>How does <code>System.ComponentModel.DataAnnotations.RequiredAttribute</code> client side validate?</p>
  
  <p>The reason to do this is because I'm using objects from classes in another project as models in my views and I don't want to add the <code>System.Web.MVC</code> reference to that project.</p>
  
  <p><strong>EDIT to add more information</strong>:</p>
  
  <ul>
  <li><p>I know that <code>IClientValidatable</code> is used to add custom attributes to
  the HTML to be used later by the unobtrusive validation.</p></li>
  <li><p>I know I'll need to add the javascript code to made the validation in
  the client.</p></li>
  </ul>
  
  <p>What I don't know is how to use the information from the custom validation attribute to add the necessary attributes to the HTML for unobtrusive validation to work.</p>
  
  <p>This is my custom validation attribute:</p>
  
  <pre><code>public class RequiredGuidAttribute : ValidationAttribute
  {
      public override bool IsValid(object value)
      {
          Guid? guidValue = value as Guid?;
  
          if (guidValue == null)
              return false;
  
          return guidValue != Guid.Empty;
      }
  }
  </code></pre>
  
  <p>This is my property with the attribute applied:</p>
  
  <pre><code>    [RequiredGuid(ErrorMessageResourceType = typeof(ClientOrderResources), ErrorMessageResourceName = "RequiredShippingMethod")]
      public Guid ShippingMethodId
      {
          get { return GetProperty(ShippingMethodIdProperty); }
          set { SetProperty(ShippingMethodIdProperty, value); }
      }
  </code></pre>
  
  <p>And finally I'm rendering a hidden input for that property in the view using <code>Html.HiddenFor</code>.</p>
  
  <p>Now, how can I get the error message from the attribute to apply it to the HTML? Should I do it my self using Reflection or there is a better way? </p>
  
  <p>And then how can I tell <code>Html.HiddenFor</code> to use that information to add the necessary attributes to the HTML?</p>