我在这个视图中创建了一个帮助方法:
@helper DisputeOpenedDays(DateTime createdDate)
{
TimeSpan difference = DateTime.Now.Subtract(createdDate);
string.Format("0", difference.Days);
}
当我像这样使用它时
@DisputeOpenedDays(myobj.CreatedAt)
它不打印任何东西
答案 0 :(得分:3)
尝试:
string.Format("{0}", difference.Days);
缺少花括号。
答案 1 :(得分:0)
@helper DisputeOpenedDays(DateTime createdDate)
{
TimeSpan difference = DateTime.Now.Subtract(createdDate);
@string.Format("{0}", difference.Days);
}
ASP.NET MVC 3 and the @helper syntax within Razor - ScottGu's Blog