,大家好,
我有一个退出的href
<a href="Home/Exit" id="exit-link">Exit</a>
我试图在单击到href时显示“确认消息”。
İf确认可以,我需要比显示Index(MainPage)进行Home / Exit会话
但是,确认不起作用,也可以获取索引页,但是只能将索引视为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);
}
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 =“退出链接” onclick =“ showmypopup()”>退出
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句