Take a look at TempData
. It's a key/value store that is good for the subsequent request and then it is destroyed.
Here is a good article on when to use it vs ViewData
and ViewBag
.
http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications
However, you should be returning strongly typed ViewModels to your view, and therefore you could have a base ViewModel that could have a message dictionary on it:
public class ViewModelBase
{
public Dictionary<string,string> Messages { get; set; }
}
And with a little extension method you could have a very easy API to display in the view:
@Model.Messages.DisplayAll()
You would have to implement DisplayAll()
, but you get the gist.