Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
尝试将 rowCounter 除以 2 时,如何在 ASP.NET Razor 中执行此操作?我收到红色下划线语法错误说“无法将类型'long'隐式转换为'bool'
long rowCounter = 0; foreach(var v in modelResult) { @:<tr class='@(rowCounter % 2 ? "even" : "odd")'> rowCounter++; }
谢谢...
问题是结果rowCounter % 2是 a long,而不是 a bool。您需要将结果与某些东西进行比较,看看rowCounter实际上是奇数还是偶数。尝试这个:
rowCounter % 2
long
bool
rowCounter
@:<tr class='@(rowCounter % 2 == 0 ? "even" : "odd")'>