我在我的应用程序中使用MVC3剃刀视图的jquery模式弹出窗口。
问题是我需要打开弹出,一旦我点击菜单选项,这些菜单选项是在布局页面(因为我需要显示它在整个网站)。由于我必须在布局弹出html代码,所以它看起来隐藏在所有的页面来源。
那么有没有更好的方法可以让我只在运行时创建弹出html呢?
我现在正在使用这个:
$(id).dialog({
closeOnEscape: true,
draggable: true,
resizable: false,
dialogClass: clz,
modal: true,
title: $(id + ' .dialog-content').attr('title'),
closeText: ''
});
发布于 2012-03-15 18:04:19
您可以使用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();
}
这是你想要的吗?
https://stackoverflow.com/questions/9717426
复制相似问题