c# - ValidationResults on TryValidateObject is null -


i trying head around data annotations.

here's class:

public class video {     [required]     public string title {get; set; }      public list<validationresult> validationresults { get; set; }      public bool isvalid()     {         var context = new validationcontext(this, null, null);         return validator.tryvalidateobject(this, context, this.validationresults);     } } 

if create object of type video without setting title, isvalid returns false (correct!), validationresults of objects null. aren't suppose contain validationresult error message saying video required or something?

to fix issue, validateallproperties parameter needs set true. e.g.

validator.tryvalidateobject(model, validationcontext, validationresults, true) 

Comments

Popular posts from this blog

xslt - Substring before throwing error -

Google Cloud Bigtable Durability/Availability Guarantees -

Android M doze mode and "native" posix socket freezing up -