我有一个类别模型,我将它用于我的电子商务系统,我为每个添加的类别都有一个固定的背景图像,我想要实现的是以编程方式为每个添加的类别添加不同的背景图像。下面是代码,目前我正在通过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%;
}
任何建议或替代方案将不胜感激,我只需要为每个类别项目添加不同的背景图像,目前背景图像固定在 datalist 使用的类别项目类中。