-1

我写的控制器如下:

public class CommodityController : Controller
{
    public ActionResult Vessel()
    {
        return View();
    }
    [GridAction]
    public ActionResult SelectVessel()
    {
        var query = _productServices.GetAllProducts().ToList();
        var model = PreparedBasicProductModel(query);
        return View(new GridModel(model));
    }

}

我写了如下观点:

@using Telerik.Web.Mvc.UI;
@using Telerik.Web.Mvc;
@model List<VesselSelection.Models.Vessel.ProductModel>

@(Html.Telerik().Grid<VesselSelection.Models.Vessel.ProductModel>()
    .Name("Grid")
     .DataBinding(dataBinding => dataBinding.Ajax().Select("SelectVessel", "Commodity")
     ) 
    .DataKeys(keys => keys.Add(c => c.Id))
    .Columns(columns =>
    {
        columns.Bound(c => c.Id).Title("Picture");
        columns.Bound(c => c.Name).Title("Data");
        columns.Bound(c => c.ProductPicture).Title("Command");
    })
    .ClientRowTemplate(grid => "<div class='employee-details'>" +
            "<img class='t-widget' src='<#= ProductPicture #>' alt='<#= Name #>' title='<#= Name #>' />" +
            "<dl>" +
                "<dt>Weight:</dt><dd><#= Weight #></dd>" +
                "<dt>Cost Price:</dt><dd><#= CostPrice #></dd>" +
                "<dt>Vendor:</dt><dd><#= VendorName #></dd>" +
        "<div class='commands'>" + grid.EditButton(null) + grid.DeleteButton(null)     +    "</div>" +
        "</div>"
    )

    .Sortable()
    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Scrollable(scrolling => scrolling.Height(500))
    .Pageable()
)

我的问题是,当我运行此应用程序时,数据未绑定,因此在网格中显示为空白。请帮我。

4

1 回答 1

2

您是否尝试过在数据绑定中使用 .OperationMode(GridOperationMode.Client) ?

例子:

.DataBinding(dataBinding => dataBinding.Ajax()
    .OperationMode(GridOperationMode.Client)
    .Select("SelectVessel", "Commodity")
 ) 

如有疑问,您可以随时查看 Telerik 的在线文档。

于 2012-11-05T16:51:44.953 回答