我需要<div>使用’forumChild’类更改标签的CSS 类。它必须每隔foreach循环的3个循环进行一次更改。
<div>
有没有一种方法可以从控件内部执行此操作?
<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; } }
凡classRed和classBlue是CSS类
classRed
classBlue