我的模特是:
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name="Email Address")]
public string Email { get; set; }
当我使用EditorFor(m=>m.Email)
时,UI(JQuery验证)会自动验证电子邮件地址。但我需要将form-control
类插入UI控件。所以我将EditorFor
更改为TextBoxFor
,如:
@Html.TextBoxFor(m => m.Email , new { @class = "form-control" })
但现在电子邮件验证无效。
如何将课程添加到EditorFor
或添加TextBoxFor
的电子邮件验证(哪种或两者都是最好的方式?)。我有其他6个属性,都很好。除此之外的一切。
答案 0 :(得分:2)
使用@ Html.TextBoxFor
示例:
@Html.TextBoxFor(x => x.Created, new { @class = "form-control" })
使用jQuery的脏方式:
$(document).ready(function () {
$('#Email').addClass('form-control');
});
答案 1 :(得分:0)
这会做你想要的......
@Html.TextBoxFor(m => m.To, new { @class = "form-control" })