【发布时间】:2010-04-14 15:09:30
【问题描述】:
我以前使用视图为我的特定项目创建一个对象,但现在我必须使其适应另一个要求,例如这个对象的创建必须集成到另一个对象的创建中。问题是,这个对象必须在开始创建另一个对象之前创建,这样做的方法是弹出一个带有 JQuery 的模式对话框,其中包含创建它的表单。我必须调整创作,它工作正常,除了验证消息。它是在控制器中制作的:
if (not.NotName.Trim().Length == 0)
{
ModelState.AddModelError("NotName", "Name is required");
}
if (_notification.checkIfExists(not.NotName, not.NotRecID))
{
ModelState.AddModelError("NotName", "Notification already exists");
}
在正常视图之前它工作得很好,但现在我无法像我一样获得验证消息。你怎么能得到这个控制器在模态框中抛出的验证消息?因为现在当我为了得到错误而故意在表单中犯了错误时,它不会出现。我已经看到错误显示在站点中,因为我在 firebug 上看到过它,但它没有出现在我的模型框中。如何检索此错误?你知道任何可以帮助我的教程吗?
javascript方法是:
function newNotificationModalBox() {
$("#newNotificationModalBox").dialog("destroy");
$("#newNotificationModalBox").dialog({
modal: true,
open: function(event, ui) {
//resetNotificationForm();
},
buttons: {
'Create': function() {
var name = document.getElementById("NotName").value;
var status = document.getElementById("NotificationStatus").value;
var replace = document.getElementById("ReplaceYes").checked;
var notificationToReplace = document.getElementById("ReplaceNotificationID").value;
var dataString = 'NotName=' + name + '&NotificationStatus=' + status + '&Replace=' + replace + '&ReplaceNotificationID=' + notificationToReplace;
$.ajax({
type: "POST",
url: "/Suspension/CreateNotification",
data: dataString
});
var list = document.getElementById("sNotification").options.length;
loadNotifications("/SearchSuspensions/LoadNotifications/", "A", "sNotification", "pNotificationName");
alert('submitting form');
//alert(document.getElementById("sNotification").options.length);
if (list != document.getElementById("sNotification").options.length) {
$(this).dialog('close');
setTimeout('selectNotificationCreated();', 100);
alert('Notification succesfully created');
}
else {
alert('Error');
}
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
}
谢谢
【问题讨论】:
标签: asp.net jquery asp.net-mvc