gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:58:34 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com