I’m displaying errors on my form with the use of
<%= Html.ValidationSummary("Please review the errors below") %>
My domain object inherits from a base class and I am finding that the base class data annotation properties are being displayed at the bottom of the list. This goes against the order in which they appear in my form.
Is there any way of specifying what order the errors should be displayed?
Example:
public class ClassA { [Required]public string AProperty; }
public class ClassB : ClassA { [Required]public string BProperty; }
My form (strongly typed view of ClassB):
AProperty: <%= Html.TextBoxFor(m => m.AProperty) %>
BProperty: <%= Html.TextBoxFor(m => m.BProperty) %>
Validation errors appear as:
The BProperty is required.
The AProperty is required.
Nope. Reflection is used to get all the DataAnnotations and they always appear in the order the properties would appear with a call to
typeof(MagicSocks).GetTYpe().GetProperties(). In your case I’m pretty sure derived class properties will always appear before base type properties.You have to write your own helper and our own attributes to display the validation errors in the order you choose.