Grid doesn't call read method after page loading. It calls it if I press on Refresh button only. What's wrong in grid configuration?
Code in .cshtml file:
@(Html.Kendo().Grid<GatherFormModel>()
.Name(
"gridGatherForm"
)
.AutoBind(
false
)
.Columns(
c =>
{
c.Bound(m => m.Id).Hidden(
true
);
c.Bound(m => m.Order).Title(
"№"
);
c.Bound(m => m.DepartmentName);
c.Bound(m => m.Name).Title(
"Name"
);
c.Bound(m => m.PeriodicityName).Title(
"Periodicity"
);
c.Bound(m => m.StateName).Title(
"State"
);
c.Bound(m => m.PeriodName).Title(
"Data range"
);
c.Bound(m => m.IsStarted).Title(
""
);
})
.Pageable(p => p.Enabled(
true
).Refresh(
true
))
.Editable(p => p.Enabled(
false
))
.Groupable(g => g.Enabled(
false
))
.DataSource(d => d.Ajax()
.PageSize(30)
.ServerOperation(
true
)
.Read(read => read.Url(Url.Action(
"Get"
,
"GatherForm"
,
new
{httproute =
""
})))
))
5 Answers, 1 is accepted
Hello Ruslan,
The reason why the DataSource does not call its read method is because the autoBind option for the Kendo UI Grid is disabled.
Regards,Boyan Dimitrov
Telerik
Can somebody help?
kendo action is not getting called.
@model IEnumerable<WebApplication1.Models.Employee.Employee>
@*<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.dataviz.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.dataviz.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.mobile.all.min.css">*@
<script src="http://code.jquery.com/Jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/ui/1.8.20/jquery-ui.min.js" type="text/javascript"></script>
<script src="~/scripts/kendo/kendo.all.min.js" type="text/javascript"></script>
<script src="~/scripts/kendo/kendo.web.min.js" type="text/javascript"></script>
<script src="~/scripts/kendo/kendo.aspnetmvc.min.js" type="text/javascript"></script>
@*<link href="~/Content/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="~/Content/kendo.default.min.css" rel="stylesheet" type="text/css" />*@
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.common.min.css">
@*<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.rtl.min.css">*@
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.default.min.css">
<script src="~/scripts/kendo/kendo.web.min.js"></script>
@(Html.Kendo().Grid<WebApplication1.Models.EmployeeviewModel>()
.Name("employeelist")
.AutoBind(true)
.Columns(columns =>
{
columns.Bound(c => c.empid);
columns.Bound(p => p.empname).Width(150);
})
.DataSource(source=>source
.Ajax()
.PageSize(5)
.Read(read=>read.Action("Read","Employee"))
)
)
controller
[HttpGet]
public ActionResult Read()
{
return View();
}
[HttpPost]
public ActionResult Read([DataSourceRequest]DataSourceRequest request)
{
IQueryable<Employee> emp = db.Employees;
DataSourceResult result=emp.ToDataSourceResult(request,e=>new EmployeeviewModel
{
empid=Convert.ToString(e.Emp_id),
empname=e.Emp_name
});
return Json(result); }
}
The reason for this behavior is because the kendo.web.min.js is loaded after the aspnetmvc.min.js script. I also noticed that there are some duplicated scripts files loaded in the page. For example there is no need to add the kendo.web.min.js two times and the kendo.all.min.js scripts. You can simply add the kendo.all.min.js and after that the kendo.aspnetmvc.min.js script.
Regards,
Boyan Dimitrov
Progress Telerik