I want to create a custom validator on the client side, but I want to define validation rules using Data Annotations attributes at the business logic level. How can I access model validation attributes at runtime?
I want to write 'generator' which converts this code:
public class LoginModel { [Required] [MinLength(3)] public string UserName { get; set; } [Required] public string Password { get; set; } }
in that:
var loginViewModel= { UserName: ko.observable().extend({ minLength: 3, required: true }), Password: ko.observable().extend({ required: true }) };
But not from .cs sources, of course. =)
Could there be a reflection?
UPD
I found this method: MSDN . But I canโt understand how to use it.
letalumil
source share