For some reason I cannot get my MVCContrib Grid sort to work.
Why does the following code results in a grid but without the sortable columns?
I'm using MVC3 and Razor syntax.
@model List<InboundShipmentItem>
@using MvcContrib.UI.Grid
@Html.Grid(Model).Sort((GridSortOptions)ViewBag.SortOptions).Columns(column =>
{
column.For(item => !item.Verified ? Ajax.ActionLink("Receive", "ReceiveItem", new {id = @item.Id},
new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "grid",
OnSuccess = "InboundShipmentVerification.ReceiveItemSucceeded",
OnFailure = "InboundShipmentVerification.ReceiveItemFailed"
}).ToString() : "Received").Named("Received?").Encode(false);
column.For(item => item.PONumber).Named("PO#").Sortable(true);
column.For(item => item.ShipQty).Named("Qty Sent").Sortable(true).SortColumnName("Qty");
column.For(item => item.ReceivedQty).Named("Qty Recd");
column.For(item => item.ISBN).Named("ISBN");
column.For(item => item.Title).Named("Title");
column.For(item => item.Author).Named("Author");
column.For(item => item.InboundShipment.Status).Named("Shipment Status");
column.For(item => item.InboundShipment.ShipmentId).Named("Shipment #");
})
The problem was that ViewBag.SortOptions was NULL. So if the GridSortOptions object is null the grid does not render any sort links for the header columns. To me this is silly behavior.