Frage

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.

War es hilfreich?

Lösung

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

Andere Tipps

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; }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top