I have a MVC page containing a few timepickers. These are stored in a list of objects in the model as nullable TimeSpan
. The problem is that I get the timespans printed with seconds into the input fields. Is there some way to format these model properties so that I get the timespans printed in some other way (like 7:00
, instead of 07:00:00
)? Needless to say, my "suggestion" of [DisplayFormat...]
didn't work. At least not the way I hoped.
The input fields are defined like this:
@Html.TextBoxFor(x => x.Shifts[i].Start)
The relevant part of the model looks like:
public class Workshift
{
[DisplayFormat(Something here perhaps?)]
public TimeSpan? Start { get; set; }
public TimeSpan? End { get; set; }
public TimeSpan? Pause { get; set; }
}
public class TimeRegistrationViewModel
{
public List<Workshift> Shifts { get; set; }
...
}
Appreciate it as always!