[英]How to validate fields using jquery in asp.net mvc 3 razor
here my code:这是我的代码:
@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();
}
Why don't you use annotation to validate the fields?为什么不使用注释来验证字段? it's much easier and cleaner, you can do as below:
它更容易和更清洁,您可以执行以下操作:
public class MyModel
{
[Required(ErrorMessage = "Please enter the Email address")]
public string Email { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.