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]