@{
var grid = new WebGrid(Model.Auctions, rowsPerPage: Model.PagingInfo.ItemsPerPage, defaultSort: "AddedDate");
}
@grid.GetHtml(
columns: grid.Columns(
**grid.Column(columnName: "", header: "Type", format: (auction) => AuctionListViewModel.GetAuctionType(auction)),**
grid.Column(columnName: "OwnerReference", header: "Owner reference")
)
);
public class AuctionListViewModel
{
public IEnumerable<Auction> Auctions { get; set; }
public IEnumerable<Item> Items { get; set; }
public PagingInfo PagingInfo { get; set; }
public string Title { get; set; }
public string Action { get; set; }
public static string GetAuctionType(Auction auction)
{
var type = string.Empty;
if (auction is LubAuction)
{
type = "Lowest unique wins";
}
else if (auction is EsfAuction)
{
type = "Highest wins";
}
return type;
}
}
With the above view code and model, get the following error on the line marked in bold, why is this?
The best overloaded method match for ‘UI.Models.AuctionListViewModel.GetAuctionType(UI.AuctionService.Auction)’ has some invalid arguments
In the
grid.Columnmethod’sformatparameter’s parameter (in your caseauction) you get the actual item (anAuction) but it’s wrapped into a dynamic wrapper called WebGridRow.You can use your properties on this wrapper and it delegates to the actual item e.g:
auction.Titlewill work, but if you want to get the whole item (theAuction) you need to use the Value property of theWebGridRow.