ASP.NET DisplayFormat dd / MM / yyyy did not work

My model

[Display(Name = "Tanggal Lahir")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime TanggalLahir { get; set; }

My opinion

@Html.EditorFor(m => m.TanggalLahir)

but the data is still saved in the format MM / dd / yyyy.

even my web.config

<system.web>
  <globalization uiCulture="en" culture="en-GB"/>
  <authentication mode="None" />
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" maxRequestLength="30000000" />
</system.web>
+4
source share
4 answers

declare your property as a string

[Display(Name = "Tanggal Lahir")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public string TanggalLahir { get; set; }
+1
source
@Html.EditorFor(m => m.TanggalLahir, "{0:dd/MM/yyyy}", new {maxlength = 10})

you can try something like this.

0
source

, .

 @Html.EditorFor(m => m.TanggalLahir, "{0:dd/MM/yyyy}", new {maxlength = 10})

()

  @Html.EditorFor(m => m.TanggalLahir, new { @Value = Model.StartDate.ToString("dd/MM/yyyy") })
0

, , . , CultureInfo .

0

Source: https://habr.com/ru/post/1613583/


All Articles