0

Is it possible to remove property name form the validation message? For example, instead of:

Field 'Name' should not be empty.

I want to show:

Field should not be empty.

I need to do this global, for all validators.

cryss
  • 4,130
  • 1
  • 29
  • 34

2 Answers2

2

easiest way would be to pass a custom message. You can also override it so it always uses that message.

[Required(ErrorMessage = "Field should not be Empty")]
public string Name { get; set; }
Peter Lea
  • 1,731
  • 2
  • 15
  • 24
2

You can do this using the localization customization like so to make the change globally. You can then of course override specific errors with a custom format if you need a one-off change.

ValidatorOptions.ResourceProviderType = typeof(MyResources);

...

public class MyResources {
   public static string notempty_error {
      get { 
          return "Field should not be empty.";
      }
   }
}
bpruitt-goddard
  • 3,174
  • 2
  • 28
  • 34