我认为我有以下 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;
它不起作用。页面未重定向,对话框仍在屏幕上。
知道我做错了什么吗?