I'm using Razor and Data Annotations in a .NET 4.5 MVC app. This is from a view model:
[Required(ErrorMessage = "Title is required.")]
[Display(Name = "Title: *")]
public string Title { get; set; }
[Display(Name = "Comments:")]
public string Comments { get; set; }
Is there a way to remove those display atributes and have a colon after the generated name (colon, space, star for a required field)? In the error messages the colon should not be shown.
You could use your own Custom display helper (similar to
LabelFor), orIf you want the LabelFor to be :
and when you have a Required attribute
you could try to use a Custom DataAnnotationsModelMetadataProvider
to use this, you have to put
in the
Application_Start()of yourGlobal.asax.csNow, I'm not sure if
metadata.DisplayNameis used in the error messages... I let you test !