私は自分の e コマース システムに使用しているカテゴリ モデルを持っています。カテゴリごとに固定の背景画像を追加しました。達成したいのは、追加したカテゴリごとに異なる背景画像をプログラムで追加することです。以下はコードです。現在、CSSを介して画像を追加しています。
@using Nop.Web.Models.Catalog;
@if (Model.Count > 0)
{
<div class="home-page-category-grid">
@(Html.DataList<CategoryModel>(Model, 5,
@<div class="item-box">
<div class="category-item"> @*Thats where i am adding background-images in the class category-item*@
<h2 class="title">
<a href="@Url.RouteUrl("Category", new { categoryId = item.Id, SeName = item.SeName })" title="@item.PictureModel.Title">
@item.Name</a>
</h2>
<div class="picture">
<a href="@Url.RouteUrl("Category", new { categoryId = item.Id, SeName = item.SeName })" title="@item.PictureModel.Title">
<img style="border-width: 0px;" alt="@item.PictureModel.AlternateText" src="@item.PictureModel.ImageUrl"
title="@item.PictureModel.Title" /></a>
</div>
</div>
</div>
))
</div>
<div class="home-page-category-grid-separator"></div>
}
カテゴリ - アイテムの Css
.home-page-category-grid .category-item
{
text-align: center;
margin: 10px 0px 35px 4px; /*width: 150px;*/
width: 166px;
height: 185px;
background: url('images/picture-bg.png') no-repeat 0 100%;
}
提案や代替案は高く評価されます.カテゴリアイテムごとに異なる背景画像を追加するだけです.現在、背景画像はデータリストで使用されるカテゴリアイテムクラスに固定されています.