Simple increment of a local variable in views in ASP.NET MVC3 (Razor)

后端 未结 5 914
借酒劲吻你
借酒劲吻你 2020-12-09 07:37

Well, this is just embarrassing. I can\'t even figure out a simple increment in one of my views in ASP.NET MVC3 (Razor). I have done searches and it appears that the docum

5条回答
  •  被撕碎了的回忆
    2020-12-09 07:54

    If all you need to do is display the numbering, an even cleaner solution is increment-and-return in one go:

    @{
       var counter = 0;
    }
    
    @foreach(var hat in Ring){

    Hat no. @(++counter)

    }

提交回复
热议问题