【发布时间】:2012-06-03 01:31:48
【问题描述】:
我的视图中有以下 jquery 代码
<script type="text/javascript">
$(document).ready(function () {
$("#dialog-confirm").dialog({
autoOpen: false,
modal: true,
resizable: false,
width: '500px'
});
$(".deleteLink").click(function (e) {
e.preventDefault();
var targetUrl = $(this).attr("href");
var dID = $(this).attr("id");
$("#dialog-confirm").dialog({
buttons: {
"Confirm": function () {
$.ajax({
url: '@Url.Action("DeleteSession")',
type: 'POST',
data: { id: dID },
success: function (data) {
window.location.herf = data.redirectToUrl;
}
});
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
$("#dialog-confirm").dialog("open");
});
});
</script>
触发对话框的这个链接是;
@Html.ActionLink("Delete", "", new { id = s.ID },new { @class = "deleteLink", id = s.ID})
控制器方法DeleteSession返回Json结果。
控制器:
[HttpPost]
public JsonResult DeleteSession(int id)
{
try
{
sRep.DeleteSession(id);
return Json(new {success = true, redirectToUrl = Url.Action("Index")});
}
catch (Exception e)
{
return Json(new {success = false, redirectToUrl = Url.Action("DisplayError", new { eerror =
"Unable to delete the course. " + "Internal error: " + e.Message})});
}
}
我检查了Json 结果,看起来还不错。唯一的问题是window.location.herf = data.redirectToUrl; 它不起作用。页面未重定向,对话框仍在屏幕上。
知道我做错了什么吗?
【问题讨论】:
-
哈哈,这不是我唯一的错别字……我显然需要离开电脑一段时间。
标签: jquery json asp.net-mvc-3 jquery-ui modal-dialog