Jquery Modal Dialog displaying MVC3 partial view - works first click only
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?
Javascript code is below (Jquery Modal Dialog):
<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.ActionLink("PopUp", "MeanQ", new { id = item.AccID }, new { id = "modal" })
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.
http://www.matthidinger.com/archive/2011/02/22/Progressive-enhancement-tutorial-with-ASP-NET-MVC-3-and-jQuery.aspx
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.
e.g.
$("#someA").click(function(){
//loads the modal and replaces #someA
});
Try using .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()
$("#someParentOfA").delegate("#someA", "click", function(){
});
Are you using MVC3? Instead of returning an "ActionResult" it might help if you return a "PartialViewResult".
精彩评论