Skip to content

san7hos/AspMvcBootstrapFlashMessages

Repository files navigation

Asp.NET Mvc Bootstrap Flash Messages

NuGet version

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.

Usage

In a controller action

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();
}

In a razor 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)

...

About

A simple TempData flash message system for Asp.net MVC

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages