title: MVC3 Validation based on Users Role
body: <p>We are using MVC3 with <em>unobstructuve</em> validation, all is fine; we got our custom validations working on the server as well as on the client.</p>
  
  <p>We are also using the build-in asp.net <strong>Role provider</strong>. We have particular Views that we use for different Roles. Some of the fields (properties of the ViewModel) are Required based on the Role of the logged-in user.</p>
  
  <p>My question is: How do we make a <strong>ValidationAttribute</strong> based on a Role? We want to make a property Required when the user is Normal User; but we don't want to make that field required when the user is an Administrator. But we do want to use the same view.</p>
  
  <p>I know we can create a custom <strong>ValidationAttribute</strong> (creating a class that derives from <strong>ValidationAttribute</strong>) I suppose that will work fine for Server-Side validation. But we really want to validate this Client-Side. </p>
  
  <p>I reckon we implement the <strong>IClientValidatable</strong> in our above <strong>ValidationAttribute</strong> and write some jQuery to make an Ajax call back to the server to check the current logged in user and its roles.
  But this will make us do an Ajax call every time the specific property changes, and the logged-in user will not change.</p>
  
  <p>What is the right way to do this? Or should we create different <strong>ViewModels</strong> for different logged in user?</p>
  
  <p>Please let me know when my above explanation doesn't make sense, I can add some example code when needed.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Thanks,</p>
  
  <p>Pim</p>