我正在查看一些示例代码,我看到了类似这样的内容:
@(Html.DataList<ProductOverviewModel>(Model, 4,
@<div class="item-box">
<div class="item">
<div class="picture">
<a href="@Url.RouteUrl("Product", new { productId = item.Id, SeName = item.SeName })" title="@item.DefaultPictureModel.Title">
<img alt="@item.DefaultPictureModel.AlternateText" src="@item.DefaultPictureModel.ImageUrl" title="@item.DefaultPictureModel.Title" /></a>
</div>
<div class="product-title">
<a href="@Url.RouteUrl("Product", new { productId = item.Id, SeName = item.SeName })" title="@item.DefaultPictureModel.Title">
@item.Name</a>
</div>
</div>
</div>
))
所以基本上有一个DataList
辅助方法的签名是这样的:
public static IHtmlString DataList<T>(this HtmlHelper helper, IEnumerable<T> items, int columns, Func<T, HelperResult> template) where T : class
他们通过了以下部分,Func<T,HelperResult> template
并且效果很好:
@<div class="item-box">
<div class="item">
<div class="picture">
<a href="@Url.RouteUrl("Product", new { productId = item.Id, SeName = item.SeName })" title="@item.DefaultPictureModel.Title">
<img alt="@item.DefaultPictureModel.AlternateText" src="@item.DefaultPictureModel.ImageUrl" title="@item.DefaultPictureModel.Title" /></a>
</div>
<div class="product-title">
<a href="@Url.RouteUrl("Product", new { productId = item.Id, SeName = item.SeName })" title="@item.DefaultPictureModel.Title">
@item.Name</a>
</div>
</div>
</div>
这是什么规则,怎么可能?