Skip to content
Flash Messages inspired by Rails
C# JavaScript Other
Find file
Latest commit 78bea9c Jul 11, 2013 @khalidabuhakmeh Merge pull request #6 from TechplexEngineer/patch-1
Make it easier to figure out what import statements are needed


Flash Messaging for ASP .NET MVC 3

Inspired by the “rails flash”

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 work.Download the source and run the sample to see all the things you can do

In The Controller

//Be sure to include these
using MvcFlash.Core;
using MvcFlash.Core.Filters;
Flash.Notice("Hey, what's up?")
Flash.Error("oh no!");
Flash.Push(new {CrazyProperty = "I'm a mad man!"});

In The View
// In The Razor View
// Simple Flash
@Html.Flash()	// Flash everything, default template: "Flash"
@Html.Flash("MyOwnTemplate") // Flash evertying, custom template
@Html.Flash((ctx) => Html.Partial("Flash", ctx)) // Flash everything, lambda
// Flash Only
@Html.FlashOnly("success") // pass in the type
@Html.FlashOnly(new [] {"success", "error"}) // pass in many types
@Html.FlashOnly(x => x.Type == "success" || x.Type == "error") // pass in a lambda
// Flash Select
@Html.FlashSelect("success") // pass in the type, default template: "Flash"
@Html.FlashSelect(x => x.Type == "success") // pass in a lambda
@Html.FlashSelect("success", "template") // pass in the type filter, and the template name	
@Html.FlashSelect(x => x.Type == "success", (ctx) => Html.Partial("Flash", ctx) ) // pass in a lambda

The Template
@model MvcFlash.Core.Models.FlashContext
<div id="@Model.Message.Type-@Model.Index" class="@Model.Message.Type">@Model.Message.Text</div>


Written by Khalid Abuhakmeh

Something went wrong with that request. Please try again.