gpt4 book ai didi

c# - 在 Razor View 中有条件地更改 CSS 类

转载 作者:IT王子 更新时间:2023-10-29 04:40:56 25 4
gpt4 key购买 nike

我需要更改 <div> 的 CSS 类标记为“forumChild”类。它必须更改 foreach 循环的每 3 个循环。

有没有办法从控件中做到这一点?

<div class="Forum">
<p>The Forum</p>

@foreach (var item in Model)
{
<div class="ForumChild">

<img src="@item.Blog.Image.img_path" alt="Not Found" />

<br />
@foreach (var comment in item.Blog.comment)
{

var db = new ACapture.Models.ACaptureDB();

var Name = from p in db.Profile.AsEnumerable()
where (p.AccountID == comment.AccountID)
select p;
<section>
<div>
<a href="@Url.Action("Index", "Home")">@foreach (var y in Name)
{ @(y.FirstName + " " + y.LastName + ":");
}</a>
</div>
<div>
@comment.Commentation
</div>
</section>
}
</div>
}
</div>

提前致谢

最佳答案

 @{
int counter=0;
}
@foreach (var item in Model)
{
counter++;
<div class="@(counter<=3 ? "classRed":"classBlue")">
<img src="@item.Blog.Image.img_path" alt="Not Found" />
//other markup also here

</div>
if (counter == 6)
{
counter = 0;
}

}

classRedclassBlue 是 CSS 类

关于c# - 在 Razor View 中有条件地更改 CSS 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11785166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com