我无法在telerik网格中绑定数据

时间:2012-11-02 14:43:06

标签: javascript telerik telerik-grid

我写了如下控制器:

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()
)

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

1 个答案:

答案 0 :(得分:2)

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

示例:

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

你可以随时查看 online documentation from telerik如有疑问。

相关问题