谢谢大家..我用简单的jquery代码调用了@onblur =“checkEmail()”:
function checkEmail() {
var mainEmail = $('#email').val();
var altEmail = $('#altEmailTxt').val();
if(mainEmail==altEmail)
{
$("#emailvalidbox").html("Email and Alternative Email should not be Same");
}
else
{
$("#emailvalidbox").html("");
}
}
答案 0 :(得分:0)
您可以在这里进行自定义验证:
您需要将以下代码放在模型顶部
[CompareTwoEmails(ErrorMessage = "Email Id Should be different")]
public class AddressModel
{
public string FirstEmail { get; set; }
public string SecondEmail { get; set; }
//Other Properties
}
您的自定义验证类:
[AttributeUsage(AttributeTargets.Class)]
public class CompareTwoEmails : ValidationAttribute
{
public override bool IsValid(object value)
{
var model = (AddressModel)value;
if (string.Equals(model.FirstEmail, model.SecondEmail, StringComparison.OrdinalIgnoreCase))
{
return false;
}
return true;
}
}
干杯!!