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
Post a Comment