admin管理员组文章数量:1330582
I have a partial view that is rendered inside of a JQuery dialog. I can easily open and close the dialog using javascript, but I can't seem to get the dialog closed from within the partial view's controller.
I thought I could just use a JavascriptResult:
return new JavaScriptResult { Script = "$(\"#popupDiv\").dialog(\"close\");" };
But that just displays the javascript in the browser.
What is the poper way to signal my JQuery dialog to close from within a controller action?
I have a partial view that is rendered inside of a JQuery dialog. I can easily open and close the dialog using javascript, but I can't seem to get the dialog closed from within the partial view's controller.
I thought I could just use a JavascriptResult:
return new JavaScriptResult { Script = "$(\"#popupDiv\").dialog(\"close\");" };
But that just displays the javascript in the browser.
What is the poper way to signal my JQuery dialog to close from within a controller action?
Share Improve this question edited May 17, 2011 at 16:23 Mike Pateras asked May 16, 2011 at 18:31 Mike PaterasMike Pateras 15k32 gold badges98 silver badges140 bronze badges1 Answer
Reset to default 6You mention partial view and javascript result, so I guess this partial view is invoked using AJAX. If this is the case you could close the dialog in the success callback:
$.ajax({
url: '/someaction',
success: function(result) {
$('#popupDiv').dialog('close');
}
});
Then you can have your controller action return a Json result indicating the success or failure of this action. Then inside the success callback you could test this value and close the dialog if everything went fine and show an error message if there was some problem:
return Json(new { success = true });
and then:
success: function(result) {
if (result.success) {
$('#popupDiv').dialog('close');
} else {
alert('Oops something went wrong, sorry');
}
}
版权声明:本文标题:javascript - How can I trigger a JQuery dialog to close from an MVC partial view's controller? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742233509a2437655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论