C#MVC3剃须刀交替项在@foreach列表? [英] C# MVC3 Razor alternating items in a @foreach list?
本文介绍了C#MVC3剃须刀交替项在@foreach列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MVC3,你如何创建使用的Razor视图引擎时@foreach名单上的交替行颜色?
@foreach(以型号VAR项){
&所述; TR>
< TD> @ item.DisplayName< / TD>
< TD> @ item.Currency< / TD>
< TD> @的String.Format({0:DD / MM / YYYY},item.CreatedOn)LT; / TD>
< TD> @的String.Format({0:绿},item.CreatedBy)LT; / TD>
< TD> @ Html.ActionLink(编辑,编辑,新{ID = item.Id})LT; / TD>
< / TR>
}
解决方案
这是什么CSS是(改变风格而不是内容)。保存在服务器的工作量:做它在客户端上
由于您使用的剃须刀,你可以使用jQuery。以下是我如何做到这一点在我的项目:
$(文件)。就绪(函数(){
$(表> TBODY TR:奇)。CSS(背景色,#F7F7F7);
}
In MVC3, how do you create alternating row colors on a @foreach list when using the Razor view engine?
@foreach (var item in Model) {
<tr>
<td>@item.DisplayName</td>
<td>@item.Currency</td>
<td>@String.Format("{0:dd/MM/yyyy}", item.CreatedOn)</td>
<td>@String.Format("{0:g}", item.CreatedBy)</td>
<td>@Html.ActionLink("Edit", "Edit", new { id = item.Id })</td>
</tr>
}
解决方案
This is what CSS is for (changing style rather than content). Save the server the effort: Do it on the client.
Since you're using Razor, you can use JQuery. Here's how I do it in my projects:
$(document).ready(function () {
$("table > tbody tr:odd").css("background-color", "#F7F7F7");
}
这篇关于C#MVC3剃须刀交替项在@foreach列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文