我有一个包含一些时间选择器的 MVC 页面。这些作为 nullable 存储在模型中的对象列表中TimeSpan
。问题是我在输入字段中打印了以秒为单位的时间跨度。有什么方法可以格式化这些模型属性,以便我以其他方式打印时间跨度(例如7:00
,而不是07:00:00
)?不用说,我的“建议”[DisplayFormat...]
没有奏效。至少不是我希望的那样。
输入字段定义如下:
@Html.TextBoxFor(x => x.Shifts[i].Start)
模型的相关部分如下所示:
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; }
...
}
一如既往地欣赏它!