在使用您的代码之前,您应该将以下代码添加到 CatalogController 中的 Category 方法:
//准备类别图片模型
int picId = category.PictureId;
int picSize = _mediaSettings.CategoryThumbPictureSize;
var categoryPicCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_PICTURE_MODEL_KEY, model.Id, picSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id);
model.PictureModel = _cacheManager.Get(categoryPicCacheKey, () =>
{
var pictureModel = new PictureModel()
{
FullSizeImageUrl = _pictureService.GetPictureUrl(picId),
ImageUrl = _pictureService.GetPictureUrl(picId, picSize),
Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), model.Name),
AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), model.Name)
};
return pictureModel;
});`