ASP MVC Customize Error Message Language

Tambahkan baris berikut di fungsi Application_Start() pada Global.asax

[code language=”csharp”]
ClientDataTypeModelValidatorProvider.ResourceClassKey = "MyGlobalErrors";
DefaultModelBinder.ResourceClassKey = "MyGlobalErrors";
[/code]

Buat MyGlobalErrors.resx di dalam folder App_GlobalResources, tambahkan nilai berikut:

  • FieldMustBeDate The field {0} must be a date.
  • FieldMustBeNumeric The field {0} must be a number.
  • PropertyValueInvalid The value ‘{0}’ is not valid for {1}.
  • PropertyValueRequired A value is required.
  • Required {0} wajib diisi

Validation message untuk Required entah kenapa tidak berfungsi. Alternatifnya mengubah kode di model menjadi

[code language=”csharp”]
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Resources.MyGlobalErrors))]
[DisplayName("Nama")]
public string Name { get; set; }
[/code]

Tambahkan baris ini di Web.config root
[code language=”xml”]
<system.web>
<globalization uiCulture="id-ID" culture="id-ID" />
[/code]

http://stackoverflow.com/questions/15377131/customize-the-error-message-mvc-for-an-invalid-datetime-in-asp-net-mvc4

Chandra Oemaryadi has written 244 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>