Format date using HtmlHelper

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 format "yyyy-mm-dd". Here's the snippet of my code:

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

How to implement?

    
asked by anonymous 30.05.2018 / 20:14

1 answer

0

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

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

or

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

Or

In your class add annotation and so you can use @Html.DisplayFor(modelItem => item.DataNascimento) that it will respect annotation

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