使用RedirectToAction时如何在视图中显示成功消息 [英] How to show success message in view when RedirectToAction used
本文介绍了使用RedirectToAction时如何在视图中显示成功消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在MVC3项目上工作,我想在视图中使用RedirectToAction时显示一条消息. 我已经使用过ViewBag,但无法正常工作.
I am working on MVC3 project and I want to show a message when I use RedirectToAction in view. I have used ViewBag but it is not working.
请任何人帮助我.
推荐答案
您可以使用TempData显示消息
you can use TempData to show the message
在您的视图中
@if (TempData["Success"] != null)
{
<p class="alert alert-success" id="successMessage">@TempData["Success"]</p>
}
以及成功后在您的控制器中
and in your controller after success
TempData["Success"] = "Added Successfully!";
return RedirectToAction("actionname", "controllername");
这篇关于使用RedirectToAction时如何在视图中显示成功消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文