Reputation: 846
my site is in mvc-4, i am opening partial view in dialog. partial view works fine first time, but when i open it second time and so on it opens he dialog but partial view is not working. I think some jquery issue i am doing wrong. In partial view div hover event is not working.
This is my code to open dialog:
<div onclick="ShowHistory();">Actions History</div>
function ShowHistory()
{
myDialog = $("<div> </div>");
myDialog.dialog({
autoOpen: false,
width: 1050,
title: "Title",
resizable: false,
modal: true,
draggable: false,
});
myDialog.load("@Url.Action("Method_return_partial_view", new {id = 1 })",
function () {
myDialog.dialog('open');
});
}
Controller method:
[Authorize]
public PartialViewResult Method_return_partial_view(int id)
{
var list = GetHistory(id);
return PartialView("_partialViewName", list);
}
Edit:
I am also sorting the grid, and grid sorting is done using jquery ajax, it works fine when open first time and controller method for sorting called once, but when i open dialog second time and i click on sorting header then controller methods called with multiple of two, means if click once then call once, if click 2nd time then controller method calls 2 times, if 3rd then calls 4 times.
Upvotes: 0
Views: 1534
Reputation: 4067
You should try and specify what happens when the dialog closes so that it can be reused again. Try this:
function ShowHistory()
{
myDialog = $("<div> </div>");
myDialog.dialog({
close: function (event, ui) {
// remove div with all data and events
myDialog.remove();
},
autoOpen: false,
width: 1050,
title: "Title",
resizable: false,
modal: true,
draggable: false,
});
myDialog.load("@Url.Action("Method_return_partial_view", new {id = 1 })",
function () {
myDialog.dialog('open');
});
}
Upvotes: 1