javascript - 如何在重定向到新 View 之前在 Controller 中创建警报提示?

标签 javascript c# asp.net-mvc

是否可以在重定向到新 View 之前在 Controller 中创建警报提示?我想让用户在将他们定向到下一个 View 之前确认当前 View 中的消息

using System.Web.Mvc;
using System.Web.Security;
using MvcApplication.Models;

[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
    if (!this.ModelState.IsValid)
    {
        return this.View(model);
    }

    if (Membership.ValidateUser(model.UserName, model.Password))
    {
        FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

***// Here! create an alert with a close button using javascript and make the user acknowledge it by clicking a button and closing the alert before redirecting the user*** 

        if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
        {
            return this.Redirect(returnUrl);
        }

        return this.RedirectToAction("Index", "Home");
    }

    this.ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect.");

    return this.View(model);
}

最佳答案

从该方法返回一些包含消息、链接和/或自动重定向的 View 。

“暂停” Controller 的处理以将消息发送回用户是不可能的!!

关于javascript - 如何在重定向到新 View 之前在 Controller 中创建警报提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43269401/

相关文章:

c# - 在javascript中访问 'mvc'数组

asp.net-mvc - ASP.NET 核心 MVC : setting expiration of identity cookie

c# - 如何传递自定义查询结果以在asp.net中查看

javascript - 元标记 "Refresh"替代 - "<?php header("位置 :.。 ?>": php echo 在 php 中的问题

javascript - 如何通过表中的 id 获取图片并将其从一个 td 移动到另一个 td?

c# - C#中如何将参数传递给另一个进程

c# - 在 ASP.NET MVC 和 Azure AD 中创建自定义用户角色

javascript - 将 Bootstrap Tokenfield 与 Bootstrap 3 Typeahead 结合使用

Javascript 替换 <li> 标签中的内容

c# - 使用 IoC 将参数从 ViewModel 传递到另一个