Asp.NET Mvc Bootstrap Flash Messages extends MVC Controllers with methods to create flash messages easily.
-
The library uses ControllerBase.TempData to store the flash messages between the requests.
-
It uses Bootstrap Alerts to display the flash messages.
Create Flash Messages using one of the 4 Controller extension methods:
FlashSuccess, FlashWarning, FlashDanger, FlashInfo
Each method has two parameters - message and its parameters - (string message, params object[] messageArgs).
using static Santhos.Web.Mvc.BootstrapFlashMessages.FlashControllerExtensions;
...
public ActionResult Index()
{
this.FlashSuccess("Password changed successfully");
var userName = "Gordon Flash";
var userId = 5;
this.FlashWarning("User {0} with Id {1} is a good person", userName, userId);
// imagine you have a resource file called Localised.resx
this.FlashInfo(Localised.MyLocalisedString, username, userId);
return this.View();
}
Show Flash Messages using HtmlHelper extension method FlashMessages(bool dismissable)
@using static Santhos.Web.Mvc.BootstrapFlashMessages
...
@*
Set dismissable to true if you want the flash messages
to be dismissable (Bootstrap feature, requires proper Bootstrap javascript)
*@
@Html.FlashMessages()
@Html.FlashMessages(true)
...