Successor to the Original MvcFlash
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
MvcFlash.Core implemented Flash Messenger with HTTP Cookie storage Nov 7, 2014

MvcFlash 2 : Flash Messaging for ASP.Net MVC 4

Bitdeli Badge

There are times where you would like to pass a message up to the view, but you aren’t sure where the redirects will end up last. That is where MvcFlash comes in. You push messages into MvcFlash and then call Flash() when you need the messages to appear. A super simple implementation that just works. Download the source and run the sample to see some of the things you can do.

** Messages are persistent and will exist as long as they are not flashed, so you will not have to worry about redirects **


Install-Package MvcFlash.Web


Install-Package MvcFlash.Core

MvcFlash.Web includes starter templates for your solution. See below.


In version 2 of MvcFlash, I have adopted multiple ways for you to implment MvcFlash into your application: Out of the Box or using IoC (DependencyResolver).

MvcFlash will attempt to resolve the interface of type [IFlashMessenger] ( from the DependencyResolver in the MVC framework. If it is not resolved, then it will end up using the default implmentation, which is the [HttpSessionFlashMessenger] ( As you may have guessed, the HttpSessionFlashMessenger uses the SessionProvider in your application.

In The Controller

Out of the Box:

Flash.Instance.Success("Well Done!", "You successfully read this important alert message.");
Flash.Instance.Warning("Warning!", "You should really read this message");
Flash.Instance.Info("Info!", "you can read this... if you want.");
Flash.Instance.Error("Error!", "The sky is falling!");

Be sure to have the following namespaces imported:

using MvcFlash.Core;
using MvcFlash.Core.Extensions;

This way works, but I recommend creating a base controller or by injecting the IFlashMessenger as a dependency.

Base Controller :

public abstract class ApplicationController : Controller
    protected virtual IFlashPusher Flash { get; private set; }

    protected ApplicationController()
        Flash = MvcFlash.Core.Flash.Instance;

In Your Views

All you need to have in your views to display your messages is the following:

@using MvcFlash.Core.Extensions;

Your messages will be displayed in Last in First Out fashion (LIFO).


Html.Flash() uses MVC's DisplayFor attribute to give you the most flexibility when templating your messages. That means you can easily create all different types of messages and corresponding views with relative ease. The default views provided for you are below and are styled to work with Twiiter Bootstrap out of the box.

SimpleMessages (the default for MvcFlash Extension Methods) :

@model MvcFlash.Core.Messages.SimpleMessage
<div class="alert alert-@Model.MessageType">
  <button type="button" class="close" data-dismiss="alert">×</button>
  <strong>@Model.Title!</strong> @Model.Content
  @if (Model.Data != null) {
    @Html.DisplayFor(m => m.Data)

MessageBase (the catch all)

@model MvcFlash.Core.Messages.MessageBase
<div class="alert alert-@Model.MessageType">
  <button type="button" class="close" data-dismiss="alert">×</button>
  <strong>@Model.Title!</strong> @Model.Content

Since Html.Flash() uses DisplayFor, you can create your own Messages (inheriting from MessageBase), and still leverage a custom template for your unique message. Examples of this can be found in the sample solution.


If you feel there should be any added features, please feel free to fork and make your additions. Also, please be sure to unit test your changes.


Khalid Abuhakmeh


  • 2.1.0 : Added HTTP Cookie Storage, thanks to @wolfascu. There are some limitations to this storage mechanism that are noted in the Pull Request.