Change the field name in ValidationSummary

I have a pretty simple input form that has some validation. I use the INotifyDataErrorInfo interface to confirm validation.

In the form, I have a combobox that is associated with a foreign key (ex ParentID).

If the check is false (the user must select an item from the list), Validationsummary displays the messages as:

ParentID Select a parent.

It's disgusting. How can I override ParentID only with parent ?

thanks for reference

+3
source share
1 answer

You can use a display attribute with the name Name changed to a friendlier text in your class:

public class Child
{
    [Display(Name="Parent")]
    public int ParentId {get;set;}

    public int ChildId {get;set;}

    public string FirstName {get;set;}

    public string LastName {get;set;}
}

DisplayAttribute System.ComponentModel.DataAnnotations. http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute.aspx

+5

All Articles