I have a VB Razor page which loops though the model's collection of listings as shown
@<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>
I want to take this exact div structure and use it in a WebGrid instead so I can take advantage of the pagentation. So it would be a Webgrid with a single column which has the above div once per row.
I am completely lost with syntax errors and function errors as most of the online help is for C#. Do I have to write a helper function that separately renders the div which I pass the model to?
For example do I have to do something like this? I wanted to keep as much formatting on the same Razor view as possible however.
@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"})
Edit -Partial View Solution?
Is this an acceptable approach to solve this?
@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"})