The following is a snippet taken from my View Model:
[Display(Name = "Time")]
[Required(ErrorMessage = "Is required field. Format hh:mm (24 hour time)")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:HH:mm}")]
public Nullable<System.TimeSpan> EventPerformance_Time { get; set; }
And this is from my View.cshtml:
<div class="form-group">
@Html.LabelFor(model => model.EventPerformance_Time, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EventPerformance_Time, "{0:HH:mm}", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EventPerformance_Time, "", new { @class = "text-danger" })
</div>
</div>
When I run the project, I keep getting the following error:
FormatException: Input string was not in a correct format.
At line @Html.EditorFor.....etc.
I have tried so many different 'solutions' and none have worked and I am so confused as to what is wrong because in another View Model it was working perfectly!
Any help please? Much appreciated.