Use a Counter with a Foreach Loop in Razor

Using bootstrap I wanted to create a two column grid with the data provided to the model. To accomplish this I needed to surround every two divs of class col-sm-6 with a div of class row. To do this I implemented a counter. I then used modulus to determine if I should open the tag or close it.

Another thing to note is that razor shows syntax errors if you just include an opening tag without its closing tag. If you run the code you will likely get a broken page complaining about missing curly braces. To get around this prepend each tag in their respective if-statements with @:.