jQuery
$(document).ready(function () {
var EmailContainer = $('#EmailContainer');
var url = EmailContainer.attr('data-url');
EmailContainer.load(url, function () {
var Emailform = $('#EmailForm');
$.validator.unobtrusive.parse(Emailform);
Emailform.submit(function () {
debugger;
var Emailform = $(this);
if (Emailform.valid()) {
var SendEmailUrl = EmailContainer.attr('Json-Url');
var UserModel = { From: $('#From').val(), To: $('#To').val(),
Subject: $('#Subject').val(),
Description: $('#Description').val() }
$.post(SendEmailUrl, UserModel, function (data) {
Emailform.html(data);
Emailform.removeData('validator');
Emailform.removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse(Emailform);
});
}
return false;
});
});
});
模型
public class User
{
[Required(ErrorMessageResourceType = typeof(Resource1),
ErrorMessageResourceName = "From")]
[DataType(System.ComponentModel.DataAnnotations.DataType.EmailAddress,
ErrorMessageResourceType = typeof(Resource1),
ErrorMessageResourceName = "InvalidEmail")]
[DisplayName("From Email Address")]
public String From { get; set; }
[Required(ErrorMessageResourceType = typeof(Resource1),
ErrorMessageResourceName = "To")]
[DataType(System.ComponentModel.DataAnnotations.DataType.EmailAddress,
ErrorMessageResourceType = typeof(Resource1),
ErrorMessageResourceName = "InvalidEmail")]
[DisplayName("To Email Address")]
public String To { get; set; }
[Required(ErrorMessageResourceType = typeof(Resource1),
ErrorMessageResourceName = "Subject")]
[DisplayName("Subject")]
public String Subject { get; set; }
[Required(ErrorMessageResourceType = typeof(Resource1),
ErrorMessageResourceName = "Description")]
[DisplayName("Description")]
public String Description { get; set; }
}
问题 - 不显示无效电子邮件地址的验证