2 回答
TA贡献1789条经验 获得超8个赞
我前段时间有同样的要求,我使用了下面的代码,看看它是否适合你。
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
@{
var first = true;
}
@foreach (var item in ViewBag.Images)
{
<div class="carousel-item @(first?Html.Raw("active"):Html.Raw(""))">
<img class="d-block w-100" src="@item.Image" alt="@item.Name">
</div>
first = false;
}
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button"
data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button"
data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
TA贡献1853条经验 获得超18个赞
请尝试这个。我希望你的问题得到解决
<div id="demo" class="carousel slide" data-ride="carousel">
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<div class="carousel-inner" role="listbox">
@{int i = 0;}
@foreach (var item in Model)
{
i++;
var active = i == 1 ? "active" : "";
<div class="carousel-item @active">
<img src="@Url.Content(@item.FilePath)" alt="">
</div>
}
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
- 2 回答
- 0 关注
- 101 浏览
添加回答
举报