7
給定一個視圖模型,看起來像這樣:如何在客戶端上將自定義ValidationAttribute呈現爲'data-val-xx'屬性?
public class Login {
[Required]
public string Username { get; set; }
[Required, CustomValidator]
public string Password { get; set; }
}
而且這樣的視圖(剃刀語法在這裏):
@Html.TextBoxFor(f => f.Password)
我得到了下面的標記:
<input type="text"
value=""
data-val-required="This field is required." />
然而我希望它還包含我的定製驗證程序的'數據'屬性。
我想是這樣的:
<input type="text"
value=""
data-val-required="This field is required."
data-val-customvalidator="XYZ" />
如何我ASP.NET MVC 3.0實現這一目標?
E.g.我是否需要在我的自定義驗證器上添加一些特殊屬性?或註冊它的地方?