At the early stages of NuGet I was worried. I was not about the idea since ruby gems is the core of Rails development, but because of the seemingly disjoint feeling of projects that were in the NuGet repository and the ones I wanted to use that were not in NuGet. Gladly the community has rallied, and now your favorite open source projects are just a click away from being in your solution. So I started looking at what I could do to contribute to this ecosystem. I sat down and looked at what I end up doing a lot and what other developers could benefit from. I also had never done a NuGet package, so this was a venture into that as well. Then it hit me, a simple flash messaging API that let’s you pass messages to your users in an ASP.NET web application. MvcFlash was born and I use it all the time now.

What it can do:

well it can flash specific kinds of messages that are helpful to your users. Below is an example of the calls you can make. Notice the simple interface, you just push a string in, but you can get fancy and push a contextual object in for that particular message. The cool thing about this as well is that you can pass anonymous objects up to the view and it will be handled correctly.

Flash.Notice("Hey, what's up?")
Flash.Error("oh no!");
Flash.Warning("sucks");
Flash.Success("WooHoo!");
Flash.Push(new {CrazyProperty = "I'm a mad man!"});

When you are ready to flash this message in your view, you just need to call.

@Html.Flash()

Simple enough, but you can get crazy with this if you need to divide your messages up into different sections.

// 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

This is very flexible and you can do very cool things with it.

What it looks like:

MvcFlash comes with a default css file and images that give you amazing looking flash messages right out of the box. If you think they look gross, then you have the ability to style them anyway you want cause MvcFlash depends on a partial view and not embeded HTML code. You have full control over the output.

What to Expect:

At it’s core MvcFlash uses Session, so these messages are resilient when it comes to redirects. They will stick around as long as you haven’t Flashed them yet. In addition, you can replace your session provider with something like the AppFabric and get flash messaging across servers (I haven’t tried this yet). My goal was to make a flexible but instantly useful API here, so you can start using it as soon as you add this package to your solution. No time to setup, or do config mashing.

Conclusion:

Download this and give it a try, you might like it. If you do like it, rate it on NuGet. If you find a bug, please file it on GitHub.