asp.net - Tutorial on using Loop Helper for WebMatrix -
i learned of nuget package loop helper webmatrix. unfortunately can't seem find documentation or project site. have information on how use or project site is?
i think supplied sample pretty covers need know, loop tracker isn't mysterious might think.
all loop.outerloop
doing referencing parent loop if you're in 1 , it's being tracked, example:
@{ int[] outerthings = new int[] {1,2,3,4}; var innerthings = new[] {"a","b","c", "d"}; foreach (int outerthing in outerthings.track()) { <li>@outerthing @foreach(var innerthing in innerthings.track()) { <li>---->@innerthing @if (loop.outerloop.first) { <strong>start of outer loop (index is: @loop.outerloop.index)</strong> } @if (loop.outerloop.last) { <strong>end of outer loop (index is: @loop.outerloop.index)</strong> } </li> } </li> } }
under bonnet helper wrapping access arrays, lists , collections , tracking forward movement through these items incrementing internal index value.
update:
here's example using 3 nested loops inner loop referencing outer loop (outerthings
):
@{ int[] outerthings = new int[] {1,2,3,4}; var middlethings = new[] { "a", "b", "c", "d" }; var innerthings = new[] { "a", "b", "c", "d" }; foreach (int outerthing in outerthings.track()) { <li>@outerthing @foreach(var middlething in middlethings.track()) { <li>---->@middlething @foreach(var innerthing in innerthings.track()) { <li>-----+---->@innerthing @if (loop.outerloop.outerloop.first) { <strong> start of outerthing loop (index is: @loop.outerloop.outerloop.index) </strong> } @if (loop.outerloop.outerloop.last) { <strong> end of outerthing loop (index is: @loop.outerloop.outerloop.index) </strong> } </li> } </li> } </li> } }
Comments
Post a Comment