Request data from Server - with MVC code behind
- Syncfusion.Core
- Syncfusion.EJ
Thanks for using Syncfusion products.
We suspect that you have not added Syncfusion DLL references under the assemblies section in Web.config file which is the cause of the issue. Please refer the following code snippets.
| <configuration> … <system.web> <compilation debug="true" targetFramework="4.5.1"> <assemblies> <add assembly="Syncfusion.EJ, Version=13.2450.0.34, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" /> <add assembly="Syncfusion.EJ.Mvc, Version=13.2500.0.34, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" /> </assemblies> </compilation> |
Please find the detailed documentation corresponding for the MVC Project where we have explained how to included Syncfusion references into the project under the section ‘Introduction -> Server side Wrappers -> ASP.NET -> Create Manually’ in the document.
Documentation Link: Introduction
From your code snippets we have also found that you have not specified adaptor in DataManager. When we are fetching data from MVC controller action we need to specify the adaptor as “UrlAdaptor”. Please refer the following code snippets.
| var dataManger = ej.DataManager({ url: "@Url.Action("_GetEmployees", "Home")", adaptor: new ej.UrlAdaptor() }); |
Please refer the following documentation link for further reference on UrlAdaptor.
https://help.syncfusion.com/js/datamanager/data-adaptors#url-adaptor
For your convenience we have created a sample and the same can be downloaded from below location.
Sample: https://www.syncfusion.com/downloads/support/forum/120037/ze/EJGrid44426244
Please let us know if you have any queries.
Regards,
Alan Sangeeth S
Hi Alan,
The libaray “Syncfusion.EJ.MVC” will be shipped to your machine only when you install Syncfusion MVC Platform controls.
We have modified the sample by not using the libraries “Syncfusion.EJ” and “Syncfusion.EJ.MVC” and the same can be downloaded from below link.
Sample: https://www.syncfusion.com/downloads/support/forum/120037/ze/EJGrid1103874756
For your information, Classes such as “DataManager”, “DataOperations” belongs to “Syncfusion.EJ” library. And as we have not referenced it in project we need to bind values, that are passed from client-side, in server-side manually and we need to perform data operations using “System.Linq”. Please refer the following code snippets.
| <div id="Grid" data-bind="ejGrid: {dataSource: data,allowPaging:true,pageSettings:{pageSize:5},allowSorting:ssort}"></div>
<script type="text/javascript"> window.employeeView = { ssort: ko.observable(true), data: ej.DataManager({ url: "/Home/_GetEmployees", adaptor: new ej.UrlAdaptor() }), };
public class HomeController : Controller { public ActionResult _GetEmployees(int skip, int take) {
var model = new NorthwindDataContext().EmployeeViews.ToList(); var count = model.Count; model = model.Skip(skip).Take(take).ToList(); return Json(new { result = model, count = count }, JsonRequestBehavior.AllowGet); } |
Regards,
Alan Sangeeth S
Query 1: “documentation about configuration with Knockout”
Please refer the following documentation for detail regarding configuration Grid Control in Knockout.
https://help.syncfusion.com/js/knockoutjs
Query 2: “want to know the ordering, filtering”
We suspect that you are asking about handling filtering and sorting queries in server side.
When we perform Grid actions like filtering,a request would be sent to server with details of filtering column in request header. Please refer the following screenshot
We can bind those params in server-side and perform corresponding actions using System.Linq. Please refer the following code snippets
| public ActionResult _GetEmployees(int skip, int take, List<Filter> where, List<Sorted> sorted) {
var model = new NorthwindDataContext().EmployeeViews.ToList();
…model = model.AsQueryable().Provider.CreateQuery(Expression.Call(typeof(Queryable), "Where", new Type[] { model.AsQueryable().ElementType }, model.AsQueryable().Expression, lambda)).Cast<EmployeeView>().ToList(); |
For your convenience we have created a sample and the same can be downloaded from below link.
Sample: https://www.syncfusion.com/downloads/support/forum/120037/ze/EJGrid-935234577
Regards,
Alan Sangeeth S
Please refer the following link for details regarding filter operation with "StartsWith".
https://stackoverflow.com/questions/8321548/expression-call-in-simple-lambda-expression-is-it-possible
Regards,
Alan Sangeeth S
- 7 Replies
- 2 Participants
-
CF Carlos Flores
- Aug 25, 2015 07:52 PM UTC
- Aug 31, 2015 05:32 AM UTC