In a ValidationSummary, why are the messages shown in a different order than the order you added errors to the ModelState and how might I fix this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
asp.net mvc is open source so you can see the code for ValidationSummary directly.
http://www.asp.net/mvc/download/
That said, I’m pretty sure ModelState is a dictionary. So if ValidationSummary is iterating over the key/values in the ModelState dictionary looking for errors the order is going to be random.
I downloaded the code at work. From ValidationSummary in MVC/Html/ValidationExtensions.cs:
So it is iterating over the values in the dictionary. And from MSDN:
and
Emphasis mine.