The <% =%> tags are just a shortcut to Response.Write. If you think about it, the lambda expression just allows you to delay the execution of the Response.Write code until the appropriate time.
, - Response.Write , , lambda, Response.Write, .
, :
public class TableBuilder
{
private Action<int> _template;
public TableBuilder Template(Action<int> template)
{
_template = template;
return this;
}
public void Render()
{
var r = HttpContext.Current.Response;
r.Write("<table>");
for(int i=0; i<10; ++i)
{
r.Write("<tr><td>");
if(_template != null)
{
_template(i);
}
r.Write("</td></tr>");
}
r.Write("</table>");
}
}
, , :
<body>
<div>
<% Html.TableBuilder().Template(i => { %>
<%= i %>: I'm a template
<% }).Render(); %>
</div>
</body>
!