在我的Kendo UI网格中,read.action()
方法没有击中。我尝试了一切。如果我错过了什么,请帮助我。
当我调试时,它甚至不会读取.action方法。在我的索引页面中,我没有做任何事情,只是返回视图。我可以看到它将转向索引方法并返回一个视图,但它没有达到read.action方法。
@(Html.Kendo().Grid<BHEBS_Web.Models.ContractorModel>()
.Name("ContractorGrid")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Contractors_Read", "Home").Type(HttpVerbs.Post)))
.Columns(columns =>
{
columns.Bound(contractor => contractor.Id);
columns.Bound(contractor => contractor.ContractorName);
columns.Bound(contractor => contractor.BHSISNum);
columns.Bound(contractor => contractor.ContractorType);
})
)
public ActionResult Contractors_Read([DataSourceRequest]DataSourceRequest request)
{
return Json(GetContractors().ToDataSourceResult(request));
}
private static IEnumerable<ContractorModel> GetContractors()
{
List<BHEBS_DAL.fContractor> lstContractors = BHEBS_BLL.Contractor.GetAllContractors();
return lstContractors.Select(contractor => new ContractorModel
{
Id = contractor.Id,
ContractorName = contractor.ContractorName,
ContractorType = contractor.ContractorType,
BHSISNum = contractor.BHSISNum
});
}
答案 0 :(得分:0)
试试这个:
[HttpPost]
public ActionResult Contractors_Read([DataSourceRequest]DataSourceRequest request)
{
return Json(GetContractors().ToDataSourceResult(request));
}
您不需要添加.Type(HttpVerbs.Post)
,默认情况下数据源会执行HttpPost。
还要确保正确加载所有脚本:
Kendo UI requires JQuery 1.9.1 to function:
<script src="~/Script/jquery-1.11.2.min.js" type="text/javascript"></script>
Ensure the Kendo scripts are loading in this order:
<script src="~/Script/kendo.all.min.js" type="text/javascript"></script>
<script src="~/Script/kendo.aspnetmvc.min.js" type="text/javascript"></script>