views:

31

answers:

1

In my model metadata class, I'm using the data annotation attributes for poperty validation. This works fine.

I have created an Attributes namespace and 4 custom validation attributes deriving from System.DataAnnotations.ValidationAttribute in it; all these attributes validate the entire model itself, because they have to compare multiple fields. I used the PropertiesMustMatch attribute as an example. I know these attributes work, because I have tested them extensively. The problem is when one of these attributes fires an error, it just re-renders the form, and once you fix the problem, you can safely submit and it works. But no error messages ever get displayed from the attributes.

My question is how can I wire up the error messages to ValidationSummary() ?

I'm using Html.ValidationSummary(true) in the views.

I can post code if it's necessary, but it would break horribly if I copied and pasted into this box since it's only about 80 characters in width and I let error message strings go off the screen most of the time.

A: 

Are you overriding the FormatErrorMessage() method in your class?

public override string FormatErrorMessage(string name)
{
   return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString,
                        OriginalProperty, ConfirmProperty);
}

FYI, paste code in with a leading four space buffer on the left and it will be formatted just fine (at least sufficient for our purposes).

AndrewDotHay