JQuery Modal Dialog showing partial view of MVC3 - only the first click works

 public ActionResult MeanQ(int id)
{            
    Access access= db.Access.Find(id);
    return PartialView("_MeanQPartial", access);
}

The partial view displayed in the above code is displayed in the JQuery dialog ... The link (onclick) that displays the partial view in the JQuery Modal dialog works well for the first click. As soon as I close this dialog box and click the link again, the Partial View does not open, as expected, in a popup form. It opens as a new page in the browser. How can I make a pop-up modal dialog connection work the same every time?

The following is the Javascript code (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 launches the modal dialog:

@Html.ActionLink("PopUp", "MeanQ", new { id = item.AccID }, new { id = "modal" })
+3
source share
3 answers

JavaScript, , - <a/> PartialView, , <a/> .

.

$("#someA").click(function(){
  //loads the modal and replaces #someA
});

.live():

$("#someA").live("click", function(){
  //loads the modal and replaces #someA, but still works since you used live()
});

, , .delegate()

$("#someParentOfA").delegate("#someA", "click", function(){

});
+1

Are you using MVC3? Instead of returning "ActionResult", this can help if you return "PartialViewResult".

0
source

All Articles