2010-04-14 30 views
1

我正在使用一個視圖爲我的特定項目創建一個對象,但現在我必須適應另一個需求,比如創建這個對象時必須集成另一個需求。問題是,必須在開始創建另一個對象之前創建該對象,並且執行此操作的方式將彈出一個帶有JQuery的模式對話框,並使用該對話框創建它。我必須調整創建,並且工作正常,除了驗證消息。它像控制器製造: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"); 
} 

,並用常規視圖前,它工作得很好,但現在我不能像我一樣得到驗證的消息。怎樣才能得到Modal Box中控制器拋出的驗證信息?因爲現在當我在表單中爲了獲得錯誤而故意犯錯時,它不會出現。我已經看到該錯誤顯示在網站上,因爲我在螢火蟲上看到它,但它沒有出現在我的模型框中。我如何檢索這個錯誤?你知道任何教程可以幫助我嗎?

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'); 
      } 
     } 
    }); 

} 

謝謝

回答

1

甲possibliity是創建呈現形式的局部視圖。然後創建一個將呈現局部視圖的動作。現在使用AJAX將部分視圖加載到模態中。發佈時,模式將通過AJAX發佈表單。當帖子返回時,您將會成功,或者它應該將表單返回給您,並允許您重新加載表單和模態中的錯誤消息。

+0

我明白你給我的步驟,其實這就是我正在做的。我的問題是,當我到達最後一部分時,我的意思是,當我必須在ajax調用之後顯示從控制器返回的表單時。有沒有辦法刷新模態以獲得這個結果?我已經發布了javascript方法,以便更清楚一些。 謝謝 – vikitor 2010-04-15 08:54:55

+0

它看起來像你使用Jquery。嘗試使用jquery.forms和ajaxSubmit功能。這有一個完整的功能,允許您編寫回發時發生的功能。 – 2010-04-15 13:08:56