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