title: Sending HTML blocks as parameters in ASP.NET MVC 4 Razor
body: <p>I've written a paginating repeater for ASP.NET MVC 4. It has a render method that takes arguments for the header, footer, body and separator sections to render, like so (much simplified for readability):</p>
  
  <pre><code>public IHtmlString Render(Func&lt;TViewModel, object&gt; header, Func&lt;TViewModel, object&gt; body, Func&lt;TViewModel, object&gt; footer)
  {
      var sb = new StringBuilder();
      // Code to render including calling the parameter objects, something like this:
      sb.Append(header(null));
      foreach (var item in items)
          sb.Append(body(item));
      sb.Append(footer(null));
  
      return new HtmlString(sb.ToString());
  }
  </code></pre>
  
  <p>Now, I want to use this method in a Razor template and include actual template parts as the parameters. This works great for a scenario like this, where I either only use a pure lambda expression or a oneliner as the template:</p>
  
  <pre><code>@Model.Render(body:
      item =&gt; Html.Partial("InvoiceListView", item)
  , separator:
      @&lt;hr /&gt;
  )
  </code></pre>
  
  <p>However, if I want to do something more complex, like structure a table and populate it, I just can't get Razor to realize that I want to send those multiple lines of template as a parameter.</p>
  
  <p>I thought that maybe this would work:</p>
  
  <pre><code>@Model.Render(body: item =&gt; 
      @&lt;text&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  @item.ArticleNr
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/text&gt;
  );
  </code></pre>
  
  <p>But no luck there. Anyone got any suggestions? Or am I tough out of luck - is it impossible to write repeaters like these in Razor?</p>