微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

重定向到ASP .NET MVC中的页面后显示通知

如何解决重定向到ASP .NET MVC中的页面后显示通知

下面是我的Ajax代码

$.ajax({
         url: '@Url.Action("AddUser","ControllerName")',dataType: 'json',contentType: 'application/x-www-form-urlencoded; charset=utf-8',type: 'POST',data: {
                //data
         },success: function (data,textStatus,jqXHR) {
               console.log(jqXHR.status);
               if (data.isSuccess) {
                   alert(data.message);
               }
               else {
                   alert(data.message);
               }
               window.location.href = "@Url.Action("Index","ControllerName")";
         },error: function (jqXHR,errorThrown) {
               console.log(jqXHR.status);
               window.location.href = "@Url.Action("Index","ControllerName")";

         }
});

我不想显示alert(data.message);,而是希望在页面加载后显示自定义通知

我不想传递任何查询字符串参数,因为它在url中可见。

有两种显示通知的方式:

1)

$(".notificationdiv").html("<div class='notification  alert alert-success' role='alert'>
<strong> Operation performed successfully</strong>
</div>");
$(".notification").fadeOut(4000);
  1. 我有一个自定义的Base Controller虚拟方法显示通知页面重定向调用方法

请让我知道如何显示通知代码示例受到赞赏。 预先谢谢你。

解决方法

使用sessionStorage

在ajax成功之前,在window.location.href之前添加

sessionStorage.successMessage= true;

并将其添加到您的jquery中

$(function () {
    if (sessionStorage.successMessage) {
        $(".notificationdiv").html("<div class='notification  alert alert-success' role='alert'><strong> Operation performed successfully</strong></div>");
        $(".notification").fadeOut(4000);
        sessionStorage.successMessage= false;
        sessionStorage.removeItem("successMessage") //if you want remove from session storage
    }
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。