在查看我从 Orchard CMS 库下载的主题时,我注意到 Layout.cshtml 文件的顶部有以下代码块:
@functions {
// To support the layout classifaction below. Implementing as a razor function because we can, could otherwise be a Func<string[], string, string> in the code block following.
string CalcuClassify(string[] zoneNames, string classNamePrefix)
{
var zoneCounter = 0;
var zoneNumsFilled = string.Join("", zoneNames.Select(zoneName => { ++zoneCounter; return Model[zoneName] != null ? zoneCounter.ToString() : ""; }).ToArray());
return HasText(zoneNumsFilled) ? classNamePrefix + zoneNumsFilled : "";
}
}
我知道声明的函数做了什么(计算填充了哪些区域以返回每列的宽度),我的问题是 - @function 块的正确用法是什么,我应该什么时候使用它?