1
The view is not recognizing the date on formed {dd MM yyyy},ex:31/12/2020 . I’m already cracking my head for hours.
*[Required]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
[Column(TypeName = "DateTime2")]
[Display(Name = "Data de Início")]
public DateTime DataInicio { get; set; }*
@Html.EditorFor(m => m.DataInicio , new { @class = "data form-control" })
Displayformat this is the format for display, the date is treated according to the culture. To avoid this an option is to use the type
string
and validate the format when receiving the model in the action– Ricardo Pontual
The question that both Textboxfor and Editorfor are reading in the form MM dd yyyy. I don’t understand this. ex: 12/31/2020 OK.
– Ivo Lima
I think you are having an error of interpretation ai... these attributes are used to render the element in the browser, displaying the date in the correct format, can render as
input
in the type correct (text, date, etc). When you will do the post, and it needs to be converted to the model that is received in the action, here we are talking about code.net
and the date has to be converted to the format that the server will understand. If Culture is mm/dd/yyyy, it is in this format that it needs to be posted, i.e., for the post what is in the input should be parsed for the model type.– Ricardo Pontual