我的类中有一个名为“ProcessingTime”的计算属性,它是根据其他属性计算的。
[Display(Name = "Processing Time (BD)")]
[DisplayFormat(DataFormatString = "{0:G0} business days")]
[NotMapped]
public int? ProcessingTime
{
get
{
if (FirstSubmissionDate == null)
{
DateTime thisDay = DateTime.Today;
return GetNumberOfWorkingDays(RegistrationDate, thisDay);
} else
{
return GetNumberOfWorkingDays(RegistrationDate, (DateTime)FirstSubmissionDate);
}
}
set { }
}
private static int GetNumberOfWorkingDays(DateTime start, DateTime stop)
{
int days = 0;
while (start <= stop)
{
if (start.DayOfWeek != DayOfWeek.Saturday && start.DayOfWeek != DayOfWeek.Sunday)
{
++days;
}
start = start.AddDays(1);
}
return days;
}
在我看来,DisplayFormat 被忽略了,它只显示一个数字。我想让它显示前。'5 个工作日'
有没有办法做到这一点?
更新:我发现它工作正常,但 DataFormat 没有出现在我的引导表中。