我有一个带有clientrow模板的Kendo UI网格,如下所示:
@(Html.Kendo().Grid(Model.UnitDetails)
.Name("grid")
.DataSource(ds => ds
.Ajax()
.Read(read => read.Action("Get", "Home"))
.AutoSync(true)
.PageSize(5)
.ServerOperation(false)
)
.RowAction(row =>
{
if (row.DataItem.ViewUnitContract.Disabled)
{
row.HtmlAttributes["style"] = "color: gray";
}
})
.Columns(columns =>
{
columns.Template(p => { }).ClientTemplate(" ").Title("Well Site");
columns.Bound(p => p.ViewUnitContract.Name).Title("Unit Name").Width(200);
columns.Template(p => { }).ClientTemplate(" ").Title("Well");
columns.Template(p => { }).ClientTemplate(" ").Title("Run").Width(75);
columns.Template(p => { }).ClientTemplate(" ").Title("Task").Width(250);
columns.Template(p => { }).ClientTemplate(" ").Title("Activity").Width(150); ;
columns.Template(p => { }).ClientTemplate(" ").Width(60).Title("Status");
columns.Template(p => { }).ClientTemplate(" ").Title("Depth (m)").Width(75);
columns.Template(p => { }).ClientTemplate(" ").Title("Speed (m/min)").Width(75);
columns.Template(p => { }).ClientTemplate(" ").Width(250).Title("Weight (kg)");
})
.ClientRowTemplate(Html.Partial("_ClientRowTemplate", Model).ToHtmlString())
.Sortable())
一个控制器,看起来像这样:
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using SomeName.Xplorer.Library.Controllers;
using SomeName.Xplorer.Services.Models;
using System.Linq;
using System.Web.Mvc;
using UnitContract = SomeName.Xplorer.Services.UnitService.UnitContract;
public class HomeController : BaseController
{
private HomeViewModel Model { get; set; }
[Authorize]
public ActionResult Index()
{
UnitContract[] listOfUnitsFromService = UnitClient.GetListOfUnits(true, "");
Model = new HomeViewModel
{
UnitDetails = GenerateUnitDetails(listOfUnitsFromService.ToList()),
};
return View(Model);
}
public ActionResult Get([DataSourceRequest] DataSourceRequest request)
{
UnitContract[] listOfUnitsFromService = UnitClient.GetListOfUnits(true, "");
Model = new HomeViewModel
{
UnitDetails = GenerateUnitDetails(listOfUnitsFromService.ToList()),
};
return Json(Model.UnitDetails.ToDataSourceResult(request));
}
}
最后,我的脚本:
<script src="@Url.Content("~/Scripts/kendo/2013.2.716/jquery.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-1.8.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/kendo/2013.2.716/kendo.all.min.js")"></script>
<script src="@Url.Content("~/Scripts/kendo/2013.2.716/kendo.aspnetmvc.min.js")"></script>
我的问题是,为什么网格实际上不使用“获取”操作?每当我调试时,它只会触发“索引”动作,就是这样。我在这里错过了什么吗? :)
答案 0 :(得分:2)
我看到了几件事:
您的网格最初是服务器绑定的。在您分页/排序/过滤等之前,它不会发出请求。这很容易解决:
@(Html.Kendo().Grid(Model.UnitDetails)
应该是
@(Html.Kendo().Grid<UnitDetail>()
你包括jQuery两次。这是多余的。只包括一个。