I have searched the doc, stackoverflow and the forum, there are many posts about JSon -> Grid issues discussed and resolved, but I couldn't really apply the approach and solve my problems from these. Have spent days on it, so, please help.
Basically I have a Grid, I am currently binding data to it with ViewBag, which is working fine.
==== controller ===
ViewBag.locationInProfile = [ a method call which returns an array of "LocationsInProfile" object]
-- definition of the LocationsInProfile object can be found below from the sample JSon data
==== Grid that works ====
==== Json controller ====
- works fine when called directly
- in debug, can see the Grid is making request to the controller with non-empty array returned
sample Json returning
[{"_id":3,"_ClientID":3,"_PrimaryLocation":5,"_SecondaryLocation":0,"_status":1,"_priority":1,"_PrimaryText":"San Jose","_SecondaryText":"None"},{"_id":1,"_ClientID":3,"_PrimaryLocation":6,"_SecondaryLocation":0,"_status":1,"_priority":1,"_PrimaryText":"Sydney","_SecondaryText":"None"},{"_id":6,"_ClientID":3,"_PrimaryLocation":6,"_SecondaryLocation":7,"_status":1,"_priority":1,"_PrimaryText":"Sydney","_SecondaryText":"Tokyo"}]
==== Json controller with DataSourceRequest ====
- works fine when called directly
- in debug, can see the Grid is making request to the controller with non-empty array returned
sample Json returning
[{"_id":3,"_ClientID":3,"_PrimaryLocation":5,"_SecondaryLocation":0,"_status":1,"_priority":1,"_PrimaryText":"San Jose","_SecondaryText":"None"},{"_id":1,"_ClientID":3,"_PrimaryLocation":6,"_SecondaryLocation":0,"_status":1,"_priority":1,"_PrimaryText":"Sydney","_SecondaryText":"None"},{"_id":6,"_ClientID":3,"_PrimaryLocation":6,"_SecondaryLocation":7,"_status":1,"_priority":1,"_PrimaryText":"Sydney","_SecondaryText":"Tokyo"}]
=================================================
Grid that would like to get working but never load any data from the controller, though in debug, we see the Grid is calling the controller action correctly and the controller is returning non-empty data array, but the Grid is n't showing anything.
Any help would be very much appreciated. I believe that it is just a small issue, but without the experience and knowing the right things to tweak, it is taking a lot of our time and effort to get it working.
Thanks in advance.
Basically I have a Grid, I am currently binding data to it with ViewBag, which is working fine.
==== controller ===
ViewBag.locationInProfile = [ a method call which returns an array of "LocationsInProfile" object]
-- definition of the LocationsInProfile object can be found below from the sample JSon data
==== Grid that works ====
@(Html.Kendo().Grid((IEnumerable<MyNameSpace.Services.LocationsInProfile>)ViewBag.locationInProfile)
.Name(
"grid"
)
.Columns(columns =>
{
columns.Bound(location => location._PrimaryText).Title(
"Primary Location"
);
columns.Bound(location => location._SecondaryText).Title(
"Secondary Location"
);
columns.Command(command => command.Custom(
"Remove"
).Click(
"RemoveLocation"
));
}
)
.Pageable()
.HtmlAttributes(
new
{ style =
"height:380px;"
})
.Scrollable()
.Sortable()
.Pageable(pge => pge
.Refresh(
true
)
.PageSizes(
true
)
)
)
==== Json controller ====
- works fine when called directly
- in debug, can see the Grid is making request to the controller with non-empty array returned
public
JsonResult ListLocationsInProfileClientID(
int
id)
{
LocationsInProfile[] res = bbc.ListLocationsInProfileClientID(id);
return
Json(res, JsonRequestBehavior.AllowGet);
}
sample Json returning
[{"_id":3,"_ClientID":3,"_PrimaryLocation":5,"_SecondaryLocation":0,"_status":1,"_priority":1,"_PrimaryText":"San Jose","_SecondaryText":"None"},{"_id":1,"_ClientID":3,"_PrimaryLocation":6,"_SecondaryLocation":0,"_status":1,"_priority":1,"_PrimaryText":"Sydney","_SecondaryText":"None"},{"_id":6,"_ClientID":3,"_PrimaryLocation":6,"_SecondaryLocation":7,"_status":1,"_priority":1,"_PrimaryText":"Sydney","_SecondaryText":"Tokyo"}]
==== Json controller with DataSourceRequest ====
- works fine when called directly
- in debug, can see the Grid is making request to the controller with non-empty array returned
public
JsonResult KendoListLocationsInProfileClientID([DataSourceRequest] DataSourceRequest request,
int
id)
{
LocationsInProfile[] res = bbc.ListLocationsInProfileClientID(id);
return
Json(res, JsonRequestBehavior.AllowGet);
}
sample Json returning
[{"_id":3,"_ClientID":3,"_PrimaryLocation":5,"_SecondaryLocation":0,"_status":1,"_priority":1,"_PrimaryText":"San Jose","_SecondaryText":"None"},{"_id":1,"_ClientID":3,"_PrimaryLocation":6,"_SecondaryLocation":0,"_status":1,"_priority":1,"_PrimaryText":"Sydney","_SecondaryText":"None"},{"_id":6,"_ClientID":3,"_PrimaryLocation":6,"_SecondaryLocation":7,"_status":1,"_priority":1,"_PrimaryText":"Sydney","_SecondaryText":"Tokyo"}]
=================================================
Grid that would like to get working but never load any data from the controller, though in debug, we see the Grid is calling the controller action correctly and the controller is returning non-empty data array, but the Grid is n't showing anything.
@(Html.Kendo().Grid<MyNameSpace.Services.LocationsInProfile>()
.Name(
"grid"
)
.Columns(columns => {
columns.Bound(location => location._PrimaryText).Title(
"Primary Location"
);
columns.Bound(location => location._SecondaryText).Title(
"Secondary Location"
);
columns.Command(command => command.Custom(
"Remove"
).Click(
"RemoveLocation"
));
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(
new
{ style =
"height:430px;"
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action(
"KendoListLocationsInProfileClientID/"
+ ViewBag.clientID,
"BackupRest"
))
)
)
Any help would be very much appreciated. I believe that it is just a small issue, but without the experience and knowing the right things to tweak, it is taking a lot of our time and effort to get it working.
Thanks in advance.