Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote my own ValidationService for MVC 1.0 by copying patterns from both xVal's DataAnnotationsRuleProvider and Microsoft's DataAnnotationsModelBinder (and Martijn's comments). The service interface is below:</p> <pre><code>public interface IValidationService { void Validate(object instance); IEnumerable&lt;ErrorInfo&gt; GetErrors(object instance); } public abstract class BaseValidationService : IValidationService { public void Validate(object instance) { var errors = GetErrors(instance); if (errors.Any()) throw new RulesException(errors); } public abstract IEnumerable&lt;ErrorInfo&gt; GetErrors(object instance); } </code></pre> <p>The service is a validation runner that walks the property tree of the object instance it receives and actually executes the validation attributes that it finds on each property, building a list of ErrorInfo objects when attributes are not valid. (I'd post the whole source but it was written for a client and I don't know yet if I'm authorized to do so.)</p> <p>You can then have your controllers, business logic services explicitly invoke validation when you are ready, rather than relying exclusively on the model binder for validation.</p> <p>There are a couple of other pitfalls that you should be aware of:</p> <ul> <li>The default DataTypeAttribute in data annotations doesn't actually do any data type validation, so you'll need to write a new attribute that actually uses xVal regular expressions (or something else) to perform server-side data type validation. </li> <li>xVal doesn't walk properties to create client-side validation, so you may want to make some changes there to get more robust client-side validation.</li> </ul> <p>If I am allowed and have time, I will try to make more source available...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload