1

出于某种原因,我无法让我的 MVCContrib Grid 排序工作。

为什么以下代码会生成网格但没有可排序的列?

我正在使用 MVC3 和 Razor 语法。

@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 #");
    })
4

2 回答 2

4
@Html.Grid(Model).Columns(column =>
{
////
}).Sort((GridSortOptions)ViewData["sort"])

您必须在控制器中填写该 ViewData。

像那样

public ActionResult Index(GridSortOptions sort, int? page)
{
   ///
   ///FILL YOUR MODEL 
   ///IEnumerable<YourModel> list = YourData.ToList() as IEnumerable<YourModel>;

    if (sort.Column == null)
    {
        sort.Column = "DefaultSortColumnName";
        sort.Direction = MvcContrib.Sorting.SortDirection.Ascending;
    }

    ViewData["sort"] = sort;

    return View(list);
}
于 2012-09-19T09:54:26.403 回答
3

问题是ViewBag.SortOptions 是 NULL。因此,如果 GridSortOptions 对象为 null,则网格不会为标题列呈现任何排序链接。对我来说,这是愚蠢的行为。

于 2012-08-23T15:28:04.820 回答