MVC3剃刀视图PopUps

问题描述:

我正在使用MVC3 Razor视图在我的应用程序中使用jquery模式弹出窗口。MVC3剃刀视图PopUps

问题是我需要打开弹出窗口,一旦我点击菜单选项,这些菜单选项有Layeout页面(因为我需要在整个网站显示它)。因为我必须在layeout上有弹出的html代码,所以它在所有页面源中都显示为隐藏。

那么有什么更好的方式可以通过我只能在运行时创建弹出html?

我现在用的这个权利:

$(id).dialog({ 
      closeOnEscape: true, 
      draggable: true, 
      resizable: false, 
      dialogClass: clz, 
      modal: true, 
      title: $(id + ' .dialog-content').attr('title'), 
      closeText: '' 
     }); 

您可以使用JQuery UI Dialog plugin并使用它通过Ajax加载模态对话框

$('#MyAtag').click(function() { 
// Add a container for the modal dialog, or get the existing one 
var dialog = ($('#ModalDialog').length > 0) ? $('#ModalDialog') : $('<div id="ModalDialog" style="display:hidden"></div>').appendTo('body'); 
// load the data via ajax 
$.get('mycontroller/myaction', {}, 
    function (responseText, textStatus, XMLHttpRequest) { 
     dialog.html(responseText); 
     dialog.dialog({ 
      bgiframe: true, 
      modal: true, 
      width: 940, 
      title: 'My Title' 
     }); 
    } 
); 
}); 

结合调用ajax'get'到链接的'click'事件。 ajax get请求从MVC项目中的相应操作返回一个局部视图,然后显示在模式对话框中。

这里的控制器可以是什么样子粗糙的例子:

public ActionResult MyAction() 
{ 
    // Do Some stuff 
    //... 

    // If the request is an ajax one, return the partial view 
    if (Request.IsAjaxRequest()) 
     return PartialView("PartialViewName"); 

    // Else return the normal view 
    return View(); 
} 

难道你想要什么?

+0

好的,谢谢,所以如果我需要弹出窗体的'表单',那么我需要在'mycontroller/myaction'返回的部分视图中为它编写html? – Aman 2012-03-15 10:09:55

+0

是的,我要编辑我的帖子。请稍等 – Razor 2012-03-15 10:14:32

+0

'dialog.html(responseText)'不会追加回复响应..因此我看到空白弹出窗口.. – Aman 2012-03-15 12:44:24