- Home
- Forum
- ASP.NET Core - EJ 2
- Grid UrlAdaptor datasource and update
Grid UrlAdaptor datasource and update
Is there some complete and full example of filling the grid with UrlAdaptor and linq to sql query with passing the parameter?
And, I want to perform CRUD actions on that grid.
Thank!
Bernard.
SIGN IN To post a reply.
6 Replies
PS
Pavithra Subramaniyam
Syncfusion Team
December 24, 2018 08:58 AM UTC
Hi Bernard,
Thanks for contacting Syncfusion support.
We have analyzed your query and We suggest you to refer to the below documentations to bind data to Grid using UrlAdaptor.
Documentations :
As we could see that you are using ASP.NET Core application. We suggest you to refer to the below general documentation link on linq to sql,
General Link : https://stackoverflow.com/questions/51671408/linq-to-sql-tools-how-to-use-it-with-asp-net-core-2-1-project
Please refer the below code example,
|
[index.cshtml]
<ejs-grid id="Grid" toolbar="@(new List<string>() {"ExcelExport", "Add", "Update", "Cancel" })">
<e-data-manager url="/Home/UrlDatasource/" updateUrl="/Home/Update/" insertUrl="/Home/Insert/" removeUrl="/Home/Delete/" adaptor="UrlAdaptor" crossdomain="true"></e-data-manager>
<e-grid-editsettings allowEditing="true" allowAdding="true"></e-grid-editsettings>
...
</ejs-grid>
[HomeController.cs]
public class HomeController : Controller
{
private NORTHWNDContext _context;
public HomeController(NORTHWNDContext context)
{
_context = context;
}
public IActionResult UrlDataSource([FromBody]DataManagerRequest dm)
{
IEnumerable DataSource = _context.Orders.Take(100).ToList();
var count = _context.Orders.AsQueryable().Count();
DataOperations operation = new DataOperations();
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
if (dm.Skip != 0)
{
DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
}
public ActionResult Insert([FromBody]EditParams value)
{
var datas = _context;
datas.Orders.Add(value.value);
datas.SaveChanges();
return Json(value);
}
public ActionResult Update([FromBody]EditParams value)
{
var db = _context;
db.Entry(value.value).State = EntityState.Modified;
db.SaveChanges();
return Json(value);
}
public ActionResult Delete([FromBody]EditParams value)
{
var db = _context;
Orders order = db.Orders.Where(c => c.OrderID == Convert.ToInt32(value.key)).FirstOrDefault();
db.Orders.Remove(order);
db.SaveChanges();
return Json(order);
}
}
|
Please get back to us if you need further assistance.
Regards,
Pavithra S.
BJ
Bernard Jurlina
December 25, 2018 07:40 AM UTC
Hi Pavithra,
and thank you for the answer. Please, can you check my other post about UrlAdaptor?
https://www.syncfusion.com/forums/141644/empty-grid-with-urladaptor
Thanks!
Bernard.
PS
Pavithra Subramaniyam
Syncfusion Team
December 26, 2018 05:18 AM UTC
Hi Bernard,
We have checked the forum #141644 and to render the Grid data, column’s field name and the data source field name should be same. Due to serialization problem, your datasource field name is changed to camel case(firmaId) and so there is a mismatch in the column’s field which is in pascal case(FirmaId). This is why you don’t have data in Grid.
To overcome this serialization problem, we suggest you to use the below solution in the Startup.cs file.
[startup.cs]
|
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
});
} |
Please get back to us if you need further assistance.
Regards,
Pavithra S.
BJ
Bernard Jurlina
December 26, 2018 08:47 AM UTC
Hi Pavithra.

Attachment: FormWebCore_e8b5eff6.rar
I tried your solution with startup.cs and now I have my grid with rendered data in it, and it is ok. But everytime when I try tu update one of the rows, the value is null, like this:
What type is the posted object on NormalUpdate if my GridDatasource is some linq to sql query?
I attached my complete solution and my database. Login is [email protected] / Lozinka1.1
Thanks!
Regards,
Bernard.
Attachment: FormWebCore_e8b5eff6.rar
BJ
Bernard Jurlina
December 26, 2018 08:48 AM UTC
PS
Pavithra Subramaniyam
Syncfusion Team
December 31, 2018 12:32 PM UTC
Hi Bernard,
Thanks for contacting Syncfusion support.
We have analyzed the screenshot and the codes you have shared with us. We could see that you have not handled CRUD model class. You need to define CRUDModel(as generic) like below code example. Please find the below code example and sample for your reference.
|
public ActionResult Update([FromBody]CRUDModel<OrdersDetails> value)
{
var ord = value.value;
...
return Json(value.value);
}
public class CRUDModel<T> where T : class
{
public T value { get; set; }
}
|
Sample : http://www.syncfusion.com/downloads/support/directtrac/general/ze/RemoteSaveAdaptor1019811572
Please refer the screenshot below,
Please get back to us if you need further assistance.
Regards,
Pavithra S.
SIGN IN To post a reply.
- 6 Replies
- 2 Participants
-
BJ Bernard Jurlina
- Dec 23, 2018 07:59 AM UTC
- Dec 31, 2018 12:32 PM UTC