We've been using Spark view engine for a while now in our application. Since the release of Resharper 6 with its great Razor support, we've caved and started to swap over.
One of the best parts of Spark was its automatic generation of variables inside a foreach loop. For instance, inside a loop you automatically get index, last, and first variables, which let you know the index, whether the item is the first item, and whether the item is the last item respectively.
My question is as follows: is there a way to have a foreach automatically generate these variables for me, so I don't have to do it manually? Do I need to create my own helper that does this?
Phil Haack wrote a nice example that will give you the items you're looking for here http://haacked.com/archive/2011/04/14/a-better-razor-foreach-loop.aspx
It's not the same as foreach
however you'll be required to do something similar if you want the features you're looking for.
HugoWare also had a great article for IEnumerable
extensions that provides the entire functionality you're looking for http://hugoware.net/blog/build-a-smarter-loop-with-c
I would probably recommend using Hugoware's example as it's more than just razor.