I am using MVC3 with Razor and EntityFramework. To handle event scheduling I have a StartDate, StartTime, EndDate, EndTime using jquery datepicker and timepicker. I am trying to use the DisplayFormatAttribute in my ViewModel but the Textbox keeps showing the entire DateTime string.
In my viewmodel I have the following properties:
[DisplayFormatAttribute(DataFormatString = "{0:mm/dd/yyyy}")]
public DateTime StartDate { get; set; }
[DisplayFormatAttribute(DataFormatString = "{0:h:mm tt}")]
public DateTime StartTime { get; set; }
And my view looks like this:
<div id="event-datetime-range" style="display:inline">
<span id="event-startdatetime">
@Html.TextBoxFor(model => model.StartDate, new { placeholder = "Start Date", id = "event-start-date", @class = "event-datepicker" });
<span class="event-timerange">at</span>
@Html.TextBoxFor(model => model.StartTime, new { placeholder = "Time", id = "event-start-time", @class = "event-timepicker event-timerange" })
</span>
Can anyone please tell me what I am doing wrong? Thanks in advance!