Razor语法中,物质循环处理,它使用到三种: for, while,foreach。
下面Insus.NET分别在ASP.NET MVC环境中列举一个例子,附加源代码:
class="code_img_closed" src="/Upload/Images/2015050710/0015B68B3C38AA5B.gif" alt="" />logs_code_hide('42ca3872-d78f-47bb-bccc-cfd0daf6d4ab',event)" src="/Upload/Images/2015050710/2B1B950FA3DF188F.gif" alt="" />while:<br /> @{ int a = 0; int b = 5; while (a < b) { @b<br /> b -= 1; } } <br /> foreach:<br /> @{ string ss = "Insus,Insus.NET,Leo,MingBo"; foreach (string s in ss.Split(',')) { @s<br /> } } <br /> for:<br /> @{ int c = 5; for (int d = 0; d <= c; d++) { @d<br /> } }View Code
动画演示: