【问题标题】:NopCommerce - Category Images not displayingNopCommerce - 类别图像未显示
【发布时间】:2013-08-15 18:13:54
【问题描述】:

我无法在 NopCommerce 主题中显示类别图片。这是我在 CategoryTemplate.ProductsInGridOrLines.cshtml 页面上使用的代码。

@if (Model.PictureModel != null && !String.IsNullOrWhiteSpace(Model.PictureModel.ImageUrl))
{
    <div class="category-picture">
        <img alt="@Model.PictureModel.AlternateText" src="@Model.PictureModel.ImageUrl" title="@Model.PictureModel.Title" />
    </div>
}

我尝试删除 if 语句,它只生成 &lt;img&gt;

【问题讨论】:

    标签: asp.net nopcommerce


    【解决方案1】:

    据我所知,应该像这样访问类别图像..

     @foreach (var item in Model.SubCategories)
                {
                    count3++;
                    <div class="sub-category-item col-4 alignCenter">
                        <h2 class="title">
                            <a href="@Url.RouteUrl("Category", new { SeName = item.SeName })" title="@item.PictureModel.Title" class="green">
                                @item.Name</a>
                        </h2>
                        <div class="picture">
                            <a href="@Url.RouteUrl("Category", new { SeName = item.SeName })" title="@item.PictureModel.Title">
                                <img alt="@item.PictureModel.AlternateText" src="@item.PictureModel.ImageUrl"
                                        title="@item.PictureModel.Title" /></a>
                        </div>
                    </div>
                     if (count3 %3 == 0)
                    {
                         @Html.Raw("</div><div class='row'>")
                    }
                }
    

    这是我目前正在处理的网站中原始 nopcommerce 代码的略微修改版本,并且此代码有效。 请注意,图片取自 item.pictureModel 而不是 Model.PictureModel。

    这是假设您没有将此代码移动到单独的文件中。

    希望对你有帮助

    【讨论】:

    • 不能让它工作,不知道为什么。它根本不显示任何内容。
    • @Rev 你能提供更多信息吗?你调试过吗?模型是否在您尝试获取图像时填充了数据?
    【解决方案2】:

    在使用您的代码之前,您应该将以下代码添加到 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;
            });`
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 2014-03-27
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      相关资源
      最近更新 更多