Javascript 我无法在telerik网格中绑定数据
我已编写了如下控制器:Javascript 我无法在telerik网格中绑定数据,javascript,telerik,telerik-grid,Javascript,Telerik,Telerik Grid,我已编写了如下控制器: public class CommodityController : Controller { public ActionResult Vessel() { return View(); } [GridAction] public ActionResult SelectVessel() { var query = _productServices.GetAllProducts().ToList
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()
)
我写了一个观点如下:
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()
)
@使用Telerik.Web.Mvc.UI;
@使用Telerik.Web.Mvc;
@模型列表
@(Html.Telerik().Grid())
.名称(“网格”)
.DataBinding(DataBinding=>DataBinding.Ajax().Select(“选择容器”、“商品”)
)
.DataKeys(keys=>keys.Add(c=>c.Id))
.列(列=>
{
columns.Bound(c=>c.Id).Title(“图片”);
columns.Bound(c=>c.Name).Title(“数据”);
columns.Bound(c=>c.ProductPicture).Title(“命令”);
})
.ClientRowTemplate(网格=>“”+
“'alt=''title='''/>”+
"" +
“重量:”+
“成本价:”+
“供应商:”+
“+grid.EditButton(null)+grid.DeleteButton(null)+”+
""
)
.Sortable()
.Editable(编辑=>editing.Mode(GridEditMode.PopUp))
.可滚动(滚动=>滚动高度(500))
.Pageable()
)
我的问题是,当我运行这个应用程序时,数据没有绑定,所以在网格中它显示为空白。
请帮助我。您是否尝试过在数据绑定中使用.OperationMode(GridOperationMode.Client) 例如:
.DataBinding(dataBinding => dataBinding.Ajax()
.OperationMode(GridOperationMode.Client)
.Select("SelectVessel", "Commodity")
)
你可以随时查看
当有疑问时