2011-01-07 76 views
1

我一直在使用本教程如何獲得一個模式的形式張貼到MVC行動

Modal Form Tutorial

現在,這個讓我儘可能的模式窗體彈出創建模式彈出登錄。沒有任何反應,當我點擊我的提交按鈕,所以我的問題是雙重的(正常形態時不在一個模式正常工作): -

  1. 我要如何提交張貼在我登錄行動我的帳戶控制器。
  2. 如何獲取任何驗證錯誤以顯示在模態中?

這是一個教程產生的腳本: -

(function ($) { 
var alog = window.console ? console.log : alert; 

$.fn.popUpForm = function (options) { 
    // REQUIRE a container 
    if (!options.container) { alert('Container Option Required'); return; } 

    // Give us someplace to attach forms 
    $("#popUpHide").length || $('<div id="popUpHide" />').appendTo('body').css('display', 'none'); 

    // Defaults and options 
    var defaults = { 
     container: '', 
     modal: true, 
     resizeable: false, 
     width: 440, 
     title: 'Website Form', 
     beforeOpen: function (container) { }, 
     onSuccess: function (container) { }, 
     onError: function (container) { } 
    }; 
    var opts = $.extend({}, defaults, options); 

    this.each(function() { 
     var $this = $(this); 

     if (!$this.is('a') || $this.attr('href') == '') { return; } 

     var SRC = $this.attr('href') + ' ' + opts.container; 

     var formDOM = $("<div />").load(SRC, function() { 
      $('#popUpHide').append(formDOM); 

      $(opts.container).dialog({ 
       autoOpen: false, 
       width: opts.width, 
       modal: opts.modal, 
       resizable: opts.resizeable, 
       title: opts.title 
      }); 

      $(opts.container).bind("submit", function (e) { 
       e.preventDefault(); 
       ajaxSubmit($this[0]); 
      }); 

      $this.bind("click", function (e) { 
       e.preventDefault(); 
       opts.beforeOpen.call($this[0], opts.container); 
       $(opts.container).dialog('open'); 
      }); 
     }); 

    }); 

    function ajaxSubmit(anchorObj) { 
     console.log(anchorObj); 
     var form = $(opts.container); 
     var method = form.attr('method') || 'GET'; 

     $.ajax({ 
      type: method, 
      url: form.attr('action'), 
      data: form.serialize(), 
      success: function() { 
       $(opts.container).dialog('close'); 
       opts.onSuccess.call(anchorObj, opts.container); 
      }, 
      error: function() { 
       opts.onError.call(anchorObj, opts.container); 
      } 
     }); 
    } 
} 
})(jQuery); 

感謝您的任何想法,

豐富

回答

0

我不知道是這樣的話,但在模態形式 - 儘量保持在與託管視圖相同的控制器中。我認爲當視圖在一個控制器上時,MVC有問題,而上面的模式使用另一個控制器。

,同時檢查以下兩篇文章:

rendering-modal-dialog-with-aspnet-mvc

graceful-modals-with-aspnet-mvc2

+0

呀控制器上是相同的。感謝Dani的鏈接,但他們已經概括了我已經有的東西,也就是說,他們得到了一個模態對話框。 – 2011-01-07 11:20:59