Pregunta

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.

¿Fue útil?

Solución

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.";
      }
   }
}

Otros consejos

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; }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top