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

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -