Format date using Htmlhelper

Asked

Viewed 175 times

0

I need the date of my model to be displayed in the "dd/mm/yyyy" format in my view, today it displays in the "yyyy-mm-dd" format. Follow the excerpt of my code:

@Html.DisplayFor(modelItem => item.DataNascimento)

As an implement?

1 answer

0

There are some options to be made, follow some of them

@Html.Label(item.DataNascimento.ToString("dd/MM/yyyy"))

or

@Html.Label(item.DataNascimento.ToShortDateString())

Or

In your class add to Annotation and so you can use the @Html.DisplayFor(modelItem => item.DataNascimento) that he will respect the Annotation

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime DataNascimento{ get; set; }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.