2248

fill kendogrid with api controller in asp.net

Question:

i use from kendo grid but my grid dont fill with values and when show page grid dont load. i use kendo 2014 and asp.net 2012. my api controller code :

public class ValuesControllerApi : ApiController { public List<File> Get() { GuaranteeEntities ef = new GuaranteeEntities(); var file = ef.Files.Where(c => c.UpdaterUserInfo == "Guarantee").ToList(); return file; } }

and my html Code is :

<div id="employeesGrid"> <script> $(function () { $("#employeesGrid").kendoGrid({ dataSource: new kendo.data.DataSource({ transport: { read: "/api/ValuesControllerApi" } }) }); }); $(function () { $("#employeesGrid").kendoGrid({ columns: [ { field: "Name" , title:"test" }, { field: "Family", title: "test test" } ], dataSource: new kendo.data.DataSource({ transport: { read: "/api/ValuesControllerApi" } }), sortable: true }); }); </script> </div>

Answer1:

Try testing your API in the browser alone.

localhost:12345/api/ValuesControllerApi <em>(change your debugging url as required)</em>

Does that work? Chances are, it doesn't. The reason is because WebApi uses a default pattern for finding the controller end point. You can find <a href="http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api" rel="nofollow">more info here</a>.

But to spare you the time, take note of this line:

<blockquote>

To find the controller, Web API adds "Controller" to the value of the {controller} variable.

</blockquote>

What this means is by default, WebApi assumes all controller classes end in "<em>Controller</em>" when trying to route to an endpoint. In your case, you have named your API ValuesControllerApi which ends in "<em>Api</em>". Remove the "<em>Api</em>" from the class name and it should work.

So, your class name should look like this: ValuesController : ApiController

and you call it like this: api/Values

Answer2:

I think that your controller action won't give Kendo Grid the results in the format it expects. You need to send it a DataSourceRequest. There is a simple example <a href="https://github.com/telerik/kendo-examples-asp-net/tree/master/grid-webapi-crud/App_Code" rel="nofollow">here</a> you may check.

Also <a href="http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/webapi-editing" rel="nofollow">this documentation article</a> should shed some light on the issue too.

Hope it helps!

Recommend

  • Regex to fetch only Key Value pairs and omit some charaters
  • Generating templates programmatically in Kendo for Angular grid
  • How to refresh kendo grid base on additional paramer
  • How to add custom keyboard navigation between editable cells in Kendo Grid
  • OpenGL Compute shader sync different work groups
  • Returning an rvalue reference from a nonlocal
  • KendoUI Grid row filter with dropdown for boolean
  • GAE Transaction in root entity
  • Can some data be separated in a Tcp connection?
  • Share HttpContext code between web and non-web application
  • Are channel sends preemption points for goroutine scheduling?
  • Is it bad to use a malloc loop to guarantee a result from malloc?
  • How can I do a 301 redirect from http to https in Wildfly 8.2?
  • Putting incomplete nested lists in a rectangular ndarray
  • ObjectMaterialize in EF not firing on first level query
  • shutdown and update job in Google Dataflow with PubSubIO + message guarantees
  • How to bind comma separated list of values to List
  • What I have to do to guarantee that ccc.jar is loaded before aaa.jar?
  • Stitching 2 images (OpenCV)
  • Is is safe to use HSQLDB for production? (JBoss AS5.1)
  • Is there a way to disable a specific event in kendo ui scheduler?
  • NHibernate manually control fetching
  • Word Open XML Mail Merge
  • How do I alternate colors in Flat List (React Native)
  • FileReader+canvas image loading problem
  • DomPDF {PAGE_NUM} not on first page
  • Insert into database using onclick function
  • Deselecting radio buttons while keeping the View Model in synch
  • Javascript simulate pressing enter in input box
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Importing jscolor library in angular 2
  • A cron job substitute?
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How to stop GridView from loading again when I press back button?
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?