0

I'm trying to use a WebGrid to display data in my model and am having a huge number of issues. My model contains among other things this:

public IEnumerable<Auction> Auctions { get; set; }

What I have done is:

@{
    var grid = new WebGrid(Model.Auctions, rowsPerPage: Model.PagingInfo.ItemsPerPage, defaultSort: "Title", canPage: true, canSort: true)
        {SortDirection = SortDirection.Ascending};
    grid.Pager(WebGridPagerModes.NextPrevious);
}

I want to display some text in the first column depending on the type of the auction in the current row, so I have written a method in the model:

public 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;
    }

Now, my view also contains:

@grid.GetHtml(
        columns: grid.Columns(
                grid.Column("OwnerReference", header: "Owner reference")

            )
        );

Question is how do I add a grid.Columns line in the above to display the text in GetAuctionType?

Also, the other issue is that there is no pager appearing and sorting does not work.

I would appreciate all help.

Thanks,

Sachin

Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304

1 Answers1

0

I would move GetAuctionType logic to a Partial Class so you can access it like a normal property on each object in your collection. You may also want to take a look at question ASP.NET MVC3 WebGrid format: parameter that is covering usage of WebGrid's column format syntax.

Regarding your other issues, do you see any errors in javascript console ?

Community
  • 1
  • 1
Paweł Staniec
  • 3,151
  • 3
  • 29
  • 41