ASP.NET MVC3 / jQuery 1.9.1 / jQuery UI 1.10.2
I've got a page on which I open a modal dialog after clicking on an Ajax.ActionLink
. Inside this dialog I have an input field and a datepicker
associated with it. When I open the dialog for the first time, I can click on the datepicker button (or inside the associated input field so it receives focus, showOn
is set to both
), and the datepicker shows as expected. I can, while the modal dialog is open, do it as often as I want to, the datepicker shows every time. When I close the modal dialog (via an attached $("ui-widget-overlay").click(function(){...});
and then open it again, the datepicker no longer works, no matter whether I try to click on the button or into the associated input field.
I tried to debug the jQuery code, and both times the lines of code being run are the same (and even though the datepicker doesn't show up the second time the dialog is opened, the jQuery methods are triggered) from what I can see in the debugger. I'm completely stumped, and the methods described in this post only helped in terms of being to show the datepicker the first time the dialog opens. Another post only seems to be related to a misunderstanding how the showOn
setting works.
I also tried to destroy the datepicker via $("#datepicker").datepicker("destroy");
when closing the dialog - to no avail. Any ideas?
Update
On the "calling page":
$(document).ready(function () {
$("#popupDialog").dialog(
{
autoOpen: false,
modal: true,
open: function()
{
$("ui-widget-overlay").click(function()
{
$("#popupDialog").dialog("close");
}
}
});
});
[...]
@Ajax.ActionLink( "Some text", "Action", "Controller", new AjaxOptions {
HttpMethod = "GET",
UpdateTargetId = "popupDialog",
InsertionMode = InsertionMode.Replace,
OnSuccess = "openPopup()"
})
[...]
function openPopup()
{
$("popupDialog").dialog("open");
}
[...]
<div id="popupDialog" style="display: none;"></div>
The controller action is very simple and as follows:
public ActionResult Action()
{
MyActionModel myActionModel = new MyActionModel();
return PartialView( myActionModel );
}
Ajax.ActionLink
which updates a target id (div) via theUpdateTargetId
property. The controller action returning the contents for the modal dialog queries a web service and then returns a partial view with a populated model.