Entity Framework DateTime format when editing entry

asp.net asp.net-mvc-5 date entity-framework

Question

I possessTimetable model, which at the time only has two properties, anId and Date . It's said as follows:

public class Timetable
{
    public int Id { get; set; }

    [Required, Column(TypeName = "Date"), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
    public DateTime Date { get; set; }
}

I next constructed some fundamental CRUD functionality, and because of theDisplayFormat I can make timetables with dates in them thanks to annotation.dd/MM/yyyy format. However, the program is populating the time slot when I make changes to an existing itinerary.Date a text box that01/01/2015 00:00:00 (See screen capture.)

enter image description here

Can I have my application use only the date instead of the date and time?

1
0
1/17/2015 11:08:11 PM

Accepted Answer

In order to display the datepicker in the browser (<input type="date" ..> ) utilizingEditorFor() The following qualities must be present on the land (note the ISO format means the date will be displayed in accordance with the browser culture)

[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode=true)]
[DataType(DataType.Date)]
public DateTime Date { get; set; }

in addition,

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

Note that older browsers, including FireFox, do not accept the HTML5 date input - here is a comparison

6
1/17/2015 11:28:11 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow