Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC Razor how can i use my HTML helper?
    primarykey
    data
    text
    <p>I have created a simple Gallery html helper, its not pretty at the moment, as I cannot get it work with Razor. (I would have liked to use Action as I would have done with the webforms viewengine)</p> <pre><code>public static HelperResult Gallery&lt;T&gt;(this HtmlHelper html, IEnumerable&lt;T&gt; items, int itemsPerRow, Action rowContainer, Func&lt;T, HelperResult&gt; itemContainer, Action endRowContainer) { if (items == null) return new HelperResult(writer =&gt; { }); int itemCount = 1; return new HelperResult(writer =&gt; { rowContainer(); foreach (var item in items) { if (itemCount % itemsPerRow == 0) { endRowContainer(); rowContainer(); } itemContainer(item).WriteTo(writer); itemCount++; } endRowContainer(); }); } </code></pre> <p>this is the intened usage, but the rowContainer and endRowContainer are outputed at the top of the generated HTML</p> <pre><code>@Html.Gallery( Model.Stores, 3, ()=&gt; { Response.Write("&lt;div class=\"portfolio_box_container\"&gt;"); }, @&lt;div class="portfolio_box" style="padding-right: 25px"&gt; &lt;img src="item.png" width="120" height="43" alt="" /&gt; &lt;/div&gt; , () =&gt; { Response.Write("&lt;/div&gt;"); }) </code></pre> <p>What im i doing wrong?</p> <p>if should print off something like:</p> <pre><code>&lt;div class="portfolio_box_container"&gt; &lt;div class="portfolio_box" style="padding-right: 25px"&gt; &lt;img src="item.png" width="120" height="43" alt="" /&gt; &lt;/div&gt; &lt;div class="portfolio_box" style="padding-right: 25px"&gt; &lt;img src="item.png" width="120" height="43" alt="" /&gt; &lt;/div&gt; &lt;div class="portfolio_box" style="padding-right: 25px"&gt; &lt;img src="item.png" width="120" height="43" alt="" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="portfolio_box_container"&gt; &lt;div class="portfolio_box" style="padding-right: 25px"&gt; &lt;img src="item.png" width="120" height="43" alt="" /&gt; &lt;/div&gt; &lt;div class="portfolio_box" style="padding-right: 25px"&gt; &lt;img src="item.png" width="120" height="43" alt="" /&gt; &lt;/div&gt; &lt;div class="portfolio_box" style="padding-right: 25px"&gt; &lt;img src="item.png" width="120" height="43" alt="" /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload