This package adds Rails-like flash functionality to your MVC controllers, backed by the excellent Toastr JavaScript notification library. Flash notifications are persisted through redirects and are removed when shown.
Best way to install is via NuGet:
PM> Install-Package RedWillow.MvcToastrFlash
This package has the following NuGet dependencies:
- Microsoft.AspNet.Mvc, version >= 3.0.20105.1
- toastr, version >= 2.1.1
First, follow the steps required to get Toastr up and working: https://www.nuget.org/packages/toastr
At the top of your layouts pages, or views that don't use layouts (that you want Toastr notifications to appear on) add:
@using RedWillow.MvcToastrFlash
And following the @RenderSection("scripts", required: false)
near the bottom add (should be right before the closing body
tag):
@Html.ToastrNotifications()
Add this using
statement:
using RedWillow.MvcToastrFlash;
Then, flash notifications to your heart's content:
public ActionResult Index()
{
this.Flash(Toastr.SUCCESS, "Welcome!", "Glad you arrived safely.");
return View();
}
See the Sample project for more usage examples.
The MVC Toastr Flash package is released under a MIT license