gpt4 book ai didi

c# - 在 Sitecore 中使用 Glassmapper 映射图像

转载 作者:太空宇宙 更新时间:2023-11-03 23:30:20 25 4
gpt4 key购买 nike

我正在尝试在 View 内的 foreach 循环中渲染图像。但是即使模型有不同的图像,它也会显示相同的图像。我在 View 中的代码:

@foreach (var currentFeature in Model.FacilityFeatures)
{
<li class="features-list-enclosure">
<span title="@currentFeature.CategoryName" class="features-list-enclosure__item">
@RenderImage(x => currentFeature.CategoryICON, new { title = @currentFeature.CategoryName }, isEditable: true)
</span>
</li>
}

我的模型:

public class FacilitiesPage : BasePage
{
[SitecoreField(FieldName = "Facility features")]
public virtual IEnumerable<ContentCategory> FacilityFeatures { get; set; }

}

当我运行调试器时,它显示 currentFeature.CategoryICON 项目在循环的每次迭代中都有不同的图像。但它在 UI 上显示相同的图像,但图像上的标题不同。如果我不使用 Glassmapper 渲染图像而不是它工作并显示不同的图像:

@foreach (var currentFeature in Model.FacilityFeatures)
{
<li class="features-list-enclosure">
<span title="@currentFeature.CategoryName" class="features-list-enclosure__item">
<img title="@currentFeature.CategoryName" src="@currentFeature.CategoryICON.Src" />

</span>
</li>
}

最佳答案

发生这种情况是因为当表达式相同时 Glass 会缓存输出。尝试使用它来渲染图像:

@RenderImage(currentFeature, x => x.CategoryICON, new { title = @currentFeature.CategoryName }, isEditable: true)

此问题与此相关:https://github.com/mikeedwards83/Glass.Mapper/issues/95

关于c# - 在 Sitecore 中使用 Glassmapper 映射图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32493191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com