Thank you tgmdbm for you answer!
I modified the class from Sergio Pereira as follow:
1 public class ValidationResult
2 {
3 public ValidationResult() { }
4
5 private Dictionary<String, String> messages = new Dictionary<String, String>();
6 public bool Success { get { return messages.Count == 0; } }
7
8 public void AddError(String field, String errorMessage)
9 {
10 messages.Add(field, errorMessage);
11 }
12
13 public Dictionary<String, String> GetErrorMessages()
14 {
15 return messages;
16 }
17 }
Then in the controller, I have:
1 TempData["validationErrors"] = validationResult.GetErrorMessages();
TempData["validationErrors"] is now a Dictionary<String, String>
How can I access each element in the .aspx view?
(ViewContext.TempData.SafeGet("validationErrors") is a String)