我有一个VB Razor页面,它循环显示模型的列表集合,如图所示
@<div class="mini-listing">
@Html.ActionLink(listing.SaleName, "Listing", New With {.id = listing.ID.ToString}, New With {.class = "mini-listing-title"})
<span class="mini-listing-location">@listing.City, @listing.State</span>
<span class="mini-listing-created">Posted - @listing.CreatedOn.ToString("MM/dd/yyyy")</span>
<span class="mini-listing-description">"@listing.SaleDescription"</span>
</div>
我想采用这个精确的div结构并在WebGrid中使用它,所以我可以利用pagentation。所以它将是一个带有单列的Webgrid,每行有一个div。
我完全迷失了语法错误和功能错误,因为大多数在线帮助都是针对C#的。我是否必须编写一个辅助函数来单独渲染我将模型传递给的div?
例如,我必须做这样的事吗?我想尽可能在同一个Razor视图上保留格式。
@Code
Dim gridListing As New WebGrid(Model.Listings)
Dim cols As New List(Of WebGridColumn)
cols.Add(gridListing.Column(format:=Function(item) Helpers.ListingDiv(item))
End code
@gridListing.GetHtml(columns:=cols,htmlAttributes:=New With {.id = "listing-schedule"})
编辑-Partial View解决方案?
这是解决这个问题的可接受方法吗?
@Code
Dim gridListing As New WebGrid(Model.Listings)
Dim cols As New List(Of WebGridColumn)
cols.Add(gridListing.Column(format:=Function(item) Html.Partial("~/Views/Sale/_minilisting.vbhtml", New ViewModels.SaleListingMinimal With {
.City = item.City,
.SaleDescription = item.SaleDescription,
.SaleName = item.SaleName}
)))
End code
@gridListing.GetHtml(columns:=cols,htmlAttributes:=New With {.id = "listing-schedule"})