Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Data Annotations with Repository
    primarykey
    data
    text
    <p>I am trying to create my own custom data annotations. I created a new project and the data annotations work perfectly in this clean project but it doesn't seem to work with my Repository-Pattern project. </p> <p>I have created a MustBeTrue validation, meaning, the method checks to see if a given checkbox is checked (terms and conditions). </p> <pre><code>[Display(Name = "I accept the terms and conditions")] [MustBeTrue(ErrorMessage = "Please accept terms and conditions before public bool AcceptTerms { get; set; } //non-relevant properties follow //....method listed below [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] public class MustBeTrueAttribute : ValidationAttribute { public override bool IsValid(object value) { return value != null &amp;&amp; value is bool &amp;&amp; (bool)value; } } </code></pre> <p>I have this exact same piece of code in a seperate project, created a view and used this model, validation works perfectly. However, when trying to replicate it in my other project, which uses a repository instead of having the model right in the web application, my custom validation does not run.</p> <p>EDIT: Another very important thing to add is that I have a helper to display the fields particular to that entity, eg, I'm using <code>MvcHtmlString</code> to return a string of the fields that need to be filled out.</p> <p>Are there any settings I must check before giving up on this? Is there anything by "default" that should hook up my custom annotations that I haven't done?</p> <p>NOTE: System.ComponentModel.DataAnnotations work fine in my repository project, it's only custom ones I can't get to work.</p> <p>Thanks for any help! Greatly appreciated.</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.
 

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