Search code examples
c#asp.net-mvcasp.net-mvc-3razorrazorengine

Stopping a Razor loop


Is there anyway to keep track of a Razor loop, and half way through it take some action, and then continue with the loop:

Eg. I have this:

@foreach (var item in Model)
{
     @Html.DisplayFor(modelItem => item.Assignee)
}

I would like (pseudo):

@var halfway = Model.count / 2
@var count = 0

@foreach (var item in Model) until count == halfway
{
     @Html.DisplayFor(modelItem => item.Assignee)
}

// hear we've reached halfway through, so I want to change add some HTML to the screen      

<hr />

@foreach remainder (var item in Model) 
{
     @Html.DisplayFor(modelItem => item.Assignee)
}

Thanks for any advice,

Mak


Solution

  •  @for(int i=0;i<= halfway ; i++)
     {
        @Html.DisplayFor(modelItem => item.Assignee)
     }