我有一个类别模型,我将它用于我的电子商务系统,每个类别都添加了一个固定的背景图像,我想实现的是以编程方式为添加的每个类别添加不同的背景图像。下面是代码,目前我正在通过CSS添加图像。使用Razor为每个类别添加不同背景图像
@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的类别-Item
.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使用的category-item类中。