对于表单验证来检查电子邮件是否存在我需要自定义验证我试过钱但没有工作它总是返回电子邮件已经存在我粘贴代码请确认我错误
jQuery 代码在视图中
<script type="text/javascript">
$(document).ready(function () {
var response;
//<!-- add vlidator -->
$.validator.addMethod(
"unique_email",function(value,element){
$.ajax({
url:'SignUp/emailExist',
type: 'POST',
data: 'email='+value,
contentType: 'application/json; charset=utf-8',
success:function(msg){
response = ( msg == 'true' ) ? true : false;
}
})
return response;
},"email already exist"
);
jQuery.validator.classRuleSettings.unique_email = { unique_email: true };
$("#register-form").validate({
submitHandler: function (form) {
$('#register-form').submit();
}
});
});
</script>
jQuery 移动代码
<div data-role="fieldcontain">
<label for="email">
<em>* </em> Email: </label>
<label> <input type="text" id="email"
name="email" class="required email unique_email" /></label>
</div>
最后是通过 ajax 使用的实际代码
[HttpPost]
public ActionResult emailExist(string email)
{
//here i m checking from db that email exist or not result will return 1
//if an email exist and 0 if not so i m return false if i found email that is on 1
int value = su.isEmailExist(email);
if (value == 1)
return Json(new { success = false});
else
return Json(new { success = true});
}
提前致谢