カスタムのクライアント側バリデーターを作成したいのですが、ビジネス ロジック レイヤーでデータ注釈属性を介して検証ルールを定義したいと考えています。実行時にモデル検証属性にアクセスするにはどうすればよいですか?
このコードを変換する「ジェネレーター」を書きたいと思います。
public class LoginModel
{
[Required]
[MinLength(3)]
public string UserName { get; set; }
[Required]
public string Password { get; set; }
}
これに:
var loginViewModel= {
UserName: ko.observable().extend({ minLength: 3, required: true }),
Password: ko.observable().extend({ required: true })
};
もちろん、.cs ソースからではありません。=)
もしかして反省?
UPD
この方法を見つけました: MSDN。しかし、使い方が理解できません。