0

,大家好,

我有一个退出的 href

<a href="Home/Exit" id="exit-link">Exit</a>

我正在尝试在单击 href 时显示确认消息。

如果确认没问题,我需要退出 Home/Exit 会话而不是显示Index(MainPage)

但是,确认不起作用,我也可以获得索引页面,但我只能将索引视为HTML(大量文本)

<script>
$(function () {
$("#exit-link").on("click", function () {
if (confirm("Are you sure you want to exit?")) {
$.ajax({
url: "/Home/Exit",
type: "POST",
dataType: "json",
contentType: 'application/json',
success: function (mydata) {
$("#Page").html(mydata);
},
error: function () {
$("#Page").html("Fail");
}
});
return false;
}
});
});

<div id="Page"></div>

我的退出操作结果

public ActionResult Exit(MyModel model)
{
int UserId = Convert.ToInt32(Session["KullaniciId"]); // User Id
if (UserId >= 1)
{
Session.Clear();
}
var stringView = RenderRazorViewToString("Index", model);
return Json(stringView, JsonRequestBehavior.AllowGet);
}
4

1 回答 1

1
    function showmypopup() {
        if (confirm("Are you sure you want to exit?")) {
            $.ajax({
                url: "/Home/Exit",
                type: "POST",
                dataType: "json",
                contentType: 'application/json',
                success: function (mydata) {
                    $("#Page").html(mydata);
                },
                error: function () {
                    $("#Page").html("Fail");
                }
            });

        }else
            return false;
    }

你应该从你的链接打个电话

a href="#" id="exit-link" onclick="showmypopup()">退出

于 2013-09-04T14:29:11.883 回答