我设法通过移动
$.validator.addMethod
和
$.validator.unobtrusive.adapters.add
showSharingView
方法。成功了,我的自定义错误显示正确。但是,我不知道为什么:
<script type="text/javascript">
var isEmailAdapterName = 'isEmail';
// client-side email validation
$.validator.addMethod(isEmailAdapterName, IsEmailValid);
// register the 'isEmail' attribute with the 'unobtrusive' validation
$.validator.unobtrusive.adapters.add(isEmailAdapterName,
[],
function(options) {
// add a 'isEmail' rule to the options so that JQuery can find it when it's checking the rules collection
options.rules[isEmailAdapterName] = {};
// add a message for the 'isEmail' rule ('message' will have the 'ShareModel' attribute 'ErrorMessage' value)
options.messages[isEmailAdapterName] = options.message;
});
function showSharingView(title, workbookId, id) {
$('.share-button').prop('disabled', true); // Disable all share buttons to avoid opening multiple dialogs
// reset the 'Emails' textarea
$('#Emails').val('');
// set the dialog's control values
$('#Title').val(title);
$('#Id').val(id);
$('#WorkbookId').val(workbookId);
// set the dialog's title
$('#dialogDisplayTitle').html("Share Workbook - " + title);
$('#shareFormModal').modal("show");
}