【发布时间】:2014-11-13 04:51:47
【问题描述】:
我发现,如果您在 IEnumerable<T> 类型的 SSVE 中公开模型上的公共属性并从该属性返回 Linq 枚举,SSVE 似乎认为该集合中没有任何值(检查 @ 987654322@,所以@Model.Values是可枚举的)。
例如,我的 C# 属性是:
public IEnumerable<string> Warnings
{
get
{
return WarningGenerators.SelectMany(w => w.GetWarnings());
}
}
在这种情况下,以下 html 根本不会出现在生成的页面中(它不存在于 DOM 中):
@If.HasWarnings
<div class="row">
<div class="col-lg-12">
@Partial['WarningsWidget.sshtml', Model.Warnings]
</div>
</div>
@EndIf
但是,如果我将 C# 更改为此(没有其他更改),html 就会显示:
public IEnumerable<string> Warnings
{
get
{
return WarningGenerators.SelectMany(w => w.GetWarnings()).ToList();
}
}
显然,对ToList() 的调用正在枚举可枚举项,然后SSVE 会拾取条目。我很惊讶 SSVE 没有枚举传递给它的集合。
这种行为是有意的吗?还是我错过了什么?
【问题讨论】: