显示 MVC3 部分视图的 Jquery 模态对话框 - 仅适用于第一次单击
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6296720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery Modal Dialog displaying MVC3 partial view - works first click only
提问by ZVenue
public ActionResult MeanQ(int id)
{
Access access= db.Access.Find(id);
return PartialView("_MeanQPartial", access);
}
The partial view thats being rendered in the above code is displayed in a Dialog Modal (Jquery)...The link(onclick) that displays the partial view in a Jquery Modal Dialog works well for the first click. Once I close that dialog and click on the link again, the Partial View does not open as expected in a pop up form. It opens as a new page in the browser. How can I make the pop up modal dialog link work the same way every time?
在上面的代码中呈现的部分视图显示在对话框模态 (Jquery) 中...在 Jquery 模态对话框中显示部分视图的链接 (onclick) 对于第一次点击效果很好。关闭该对话框并再次单击该链接后,部分视图不会在弹出表单中按预期打开。它在浏览器中作为新页面打开。如何使弹出的模态对话框链接每次都以相同的方式工作?
Javascript code is below (Jquery Modal Dialog):
Javascript 代码如下(Jquery 模态对话框):
<script type="text/javascript">
$(document).ready(function () {
//initialize the dialog
$("#result").dialog({ width: 400, resizable: true, position: 'center', title: 'Access info', autoOpen: false,
buttons: { "Ok": function () { $(this).dialog("close"); } }
});
});
$(function () {
$('#modal').click(function () {
//load the content from this.href, then turn it into a dialog.
$('#result').load(this.href).dialog('open');
return false;
});
});
HTML Link that triggers the modal dialog:
触发模态对话框的 HTML 链接:
@Html.ActionLink("PopUp", "MeanQ", new { id = item.AccID }, new { id = "modal" })
回答by Maheep
Recently I also faced a slimier problem where I wanted to use both partial and full razor view. I followed following article to implement my Modal Dialog. And it worked fine.
最近我还遇到了一个更棘手的问题,我想同时使用部分和完整的剃刀视图。我按照以下文章来实现我的模态对话框。它工作得很好。
回答by Mark Coleman
Without knowing your JavaScript, my guess is you are somehow replacing the <a/>
element when loading the PartialView
since you mention the <a/>
does the default action after loading the modal.
在不了解您的 JavaScript 的情况下,我的猜测是您<a/>
在加载时以某种方式替换了元素,PartialView
因为您提到了<a/>
加载模态后的默认操作。
e.g.
例如
$("#someA").click(function(){
//loads the modal and replaces #someA
});
Try using .live()
:
尝试使用.live()
:
$("#someA").live("click", function(){
//loads the modal and replaces #someA, but still works since you used live()
});
Even better if the element has a common parent, you can use .delegate()
如果元素有一个共同的父元素,那就更好了,你可以使用 .delegate()
$("#someParentOfA").delegate("#someA", "click", function(){
});
回答by mymex1
Are you using MVC3? Instead of returning an "ActionResult" it might help if you return a "PartialViewResult".
你在使用MVC3吗?如果您返回“PartialViewResult”,它可能会有所帮助,而不是返回“ActionResult”。