Reputation: 3521
I want my input to show as dd/mm/yyyy, how i can i change by default?
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "dd/MM/yyyy")]
public DateTime Date{ get; set; }
html
<input asp-for="Process.Date" class="form-control" />
Upvotes: 0
Views: 806
Reputation: 239290
I'm assuming that what you're actually referring to is the HTML5 date input and how it's rendered by browsers. What you're seeing is localized, but it's localized based on the culture set on the client machine. In other words, you can't control this from the server. That's actually the way it should be. The end-user decides their own culture preferences. Additionally, the date input type doesn't support any date format but ISO (YYYY-MM-DD). Passing a date formatted in any other way will be treated as a null value.
If you don't want this behavior, your only choice is to use a regular text input, which you can achieve by manually specifying the type
attribute:
<input type="text" asp-for="Process.Date" class="form-control" />
However, when you do this, it's just a regular text input. You will get no date picker control, validation, etc. You'll need to rely on third-party JS libraries to add back in this functionality client-side, if you desire it.
Upvotes: 2