2012-03-29 27 views
0

我有一個內置窗體的fancybox彈出窗口。當表單發佈後,它可以正常工作,但是在發佈後重定向到視圖並在整頁上顯示。ASP.NET MVC如何關閉表單上的fancybox

我想要的是彈出窗口被張貼和花式框被關閉。

這裏是我的代碼

主頁這將打開彈出式細

<%: Html.ActionLink("Add Person Box", "AddTest", Nothing, New With {.class = "fbox"})%> 

    <script type="text/javascript"> 
     $(document).ready(function() { 

      $(".fbox").fancybox(); 

     }); 
    </script> 

彈出頁面

<% Using Html.BeginForm() %> 
    <input type="submit" value="Save Person" /> 

<% End Using %> 

這再次提交不錯,但重定向到自身在全屏模式下。我只想要表格被張貼,而花哨的盒子被關閉。

回答

0

嘗試添加屬性onsubmit="javascript:parent.jQuery.fancybox.close();""form標籤

+0

我試過了,但形式不提交和的fancybox不收任何 – 2012-03-29 20:16:43

+0

任何其他的想法? – 2012-03-29 20:16:54

+0

看到我編輯的答案 – JFK 2012-03-29 23:18:26

0

爲了避免重定向,你需要使它成爲一個Web方法。

0

使用jQuery ajax發佈Popup表單的內容。從服務器操作方法獲得響應後,使用javascript關閉它。

0

我會使用JQuery Form插件。劫持表單並執行ajax請求。請求完成後,您可以關閉回調函數中的奇特框(只要沒有錯誤)。

http://jquery.malsup.com/form/

// bind to the form's submit event 
$('#myForm2').submit(function() { 
    // inside event callbacks 'this' is the DOM element so we first 
    // wrap it in a jQuery object and then invoke ajaxSubmit 
    $(this).ajaxSubmit({ 
     success : function (result) { $.fancybox.close() } 
    }); 

    // !!! Important !!! 
    // always return false to prevent standard browser submit and page navigation 
    return false; 
});