Reputation: 327
As per the requirement, I am having a Kendo UI grid on my VIEW.But sadlyy, the read function is not being hit in the controller.This is annoying ,I am getting the same problem even though everyhting seems to be as per the documentation provided on http://demos.kendoui.com/web/grid/index.html. Here is my View code:
@(Html.Kendo().Grid<StudentManagement_Models.Student>()
.Name("studentsGrid")
.Columns(columns =>
{
columns.Bound(p => p.Id).Groupable(false);
columns.Bound(p => p.FirstName);
columns.Bound(p => p.MiddleName);
columns.Bound(p => p.LastName);
columns.Bound(p => p.CGPA);
})
.AutoBind(true)
.Pageable()
.Navigatable()
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetAllStudents", "Student"))
)
)
Here is my controller action:
public ActionResult GetAllStudents([DataSourceRequest] DataSourceRequest request)
{
//Thread.Sleep(2000);
StudentManagement_Models.Student student = new StudentManagement_Models.Student();
StudentHelper helper = new StudentHelper();
student.SavedStudents = helper.GetAllStudents();
return Json(student.SavedStudents.ToDataSourceResult(request));
}
How would I tackle this ?Am I missing something ?Kindly suggest.
Thanks in advance.
Upvotes: 4
Views: 20043
Reputation: 4840
I discovered that if there are two grids on the same webpage (in this case, in different tabs), then each grid MUST have its own datasource method in the MVC controller - even if both grids are using the same data,
Upvotes: 0
Reputation: 21
"By default Kendo Grid for ASP.NET MVC should make POST requests when configured for ajax binding. " ??? For Kendo UI version 2014.1.318, I think, by default Kendo Grid for asp.net mvc makes GET requests when configured for ajax binding.
Upvotes: 2
Reputation: 13106
I was having similar issue with the MVC version.
I noticed I was getting a 404 but when clicking the 404'd link in the Chrome debugger it would indeed hit my controller method. Then I noticed that it was using POST (and I had HttpVerbs.Get) specified.
Then I found this (from http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/troubleshooting):
By default Kendo Grid for ASP.NET MVC should make POST requests when configured for ajax binding. This is implemented by a custom DataSource transport and schema. Those are defined in the kendo.aspnetmvc.min.js. Make sure that this file is included after the other Kendo JavaScript files.
After verifying that the scripts were indeed in the correct order (and knowing it probably had something to with POST) I specified the verb to use at the end of my Read in the grid as so:
.Read(read => read.Action("MyList_Read", "Diagnosis").Type(HttpVerbs.Get))
This solved MY problem.
Upvotes: 5
Reputation: 8020
Add all of this file in your page
<script src="~/Script/Jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="~/Script/jquery-ui-1.8.20.min.js" type="text/javascript"></script>
<script src="@Url.Content("~/Script/kendo.all.min.js")" type="text/javascript"></script>
<script src="~/Script/kendo.web.min.js" type="text/javascript"></script>
<script src="~/Script/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" />
I think you mis one of the js
in your page , probebly Jquery-1.8.1.min.js
.
Upvotes: 6
Reputation: 415
try to call the read method with JQuery's document.ready()
$(document).ready(function ()
{
var grid = $("#studentsGrid").data("kendoGrid")
grid.dataSource.read()
})
Also is savedStudent a type of student.... Ur grid is bound to Student but you are returning SavedStudent objects
Upvotes: 3