c# - 15 秒后自动隐藏 C# 中的 ViewBag 消息

标签 c# viewbag

我正在 C# 中通过 ViewBag 显示一条消息,它工作正常。现在我想要的是 15 秒后自动隐藏 ViewBag 消息。我该怎么做?

以下是我使用 ViewBag 的代码:

public ActionResult ForgetPassword(String EmailId, string message)
    {
        ViewBag.Message = message;
        ForgetPassword objForgetPassword = new ForgetPassword { EmailId = EmailId };
        return View();
    }

//我传递消息的其他模型

 if (objResult.Status)
            {
                return RedirectToAction("Login", new { message = "Password changed Successfully. Please Login with the New Password."});
            }

相同的CSHTML代码:

@using (Html.BeginForm()) 
{
@Html.AntiForgeryToken()

<div class="form-horizontal for-pass">
    <h4><b>@ViewBag.Message</b></h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(model => model.OTP, htmlAttributes: new { @class = "control-label" })
        <div class="col-md-12">
            @Html.EditorFor(model => model.OTP, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.OTP, "", new { @class = "text-danger" })
        </div>
    </div>

最佳答案

您可以使用 javascript setTimeout函数来运行代码以使用查询 fadeOut 隐藏消息功能:

$(document).ready(function(){
    setTimeout(function(){
        $("#msg").fadeOut();
    }, 15000);
});

并在 View 中:

<h4 id="msg"><b>@ViewBag.Message</b></h4>

这是 fiddle :https://dotnetfiddle.net/3Sw1O9

关于c# - 15 秒后自动隐藏 C# 中的 ViewBag 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52941952/

相关文章:

asp.net-mvc - 为什么VS无法识别标准的MVC组件,例如ViewBag,@ Html.ActionLink等?

确认消息框中的 ASP.NET MVC ViewBag

c# - 我如何从 JS 访问 ViewBag

c# - “Tempdata”在当前上下文中不存在

c# - 在 Unity 中使用 OpenCVSharp 进行眼睛检测(fps 问题)

c# - 如何为 ECDiffieHellmanCng 导出私钥

c# - Azure 虚拟助手提示按钮

c# - 使用 C# 制作 SQL Server 插件

c# - .NET 中的验证框架,可以在字段之间进行编辑

asp.net-mvc-3 - 为什么不大量使用 ViewBag?