[英]How to validate fields using jquery in asp.net mvc 3 razor
這是我的代碼:
@using (Html.BeginForm("Register", "User", FormMethod.Post, new { id = "RegisterForm" }))
{
@Html.TextBoxFor(m => m.EmailAddress,
new { size = "40",
@onchange = "UserNameVal();",
@tabindex = "1" })
}
$("#RegisterForm").validate({
rules: {
EmailAddress: {
required: true
}
},
messages: {
EmailAddress: {
required: "<br/> Please enter the Email address"
}
}
});
if ($("#RegisterForm").valid()) {
$("#RegisterForm").submit();
}
為什么不使用注釋來驗證字段? 它更容易和更清潔,您可以執行以下操作:
public class MyModel
{
[Required(ErrorMessage = "Please enter the Email address")]
public string Email { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.