Hi,
I have used your Grid control for the first time in a Visual Studio 19 proyect and it is listing the items in the DataTable, it does updates them, but it fails to Insert new one or deleting.
I have added the controller with the "Syncfusion ASP.NET Core UI Scaffolder" so the code was generated automatically. I don´t know what I am doing wrong,
Thanks for your support.
|
Index.cshtml
<ejs-grid id="Grid" allowPaging="true" allowFiltering="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<e-grid-filterSettings type="Menu"></e-grid-filterSettings>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal" showConfirmDialog="true" showDeleteConfirmDialog="true"></e-grid-editSettings>
<e-data-manager url="/Home/TelecomDataSource" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Delete" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-columns>
<e-grid-column field="ShipCity" headerText="ShipCity" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" width="120"> </e-grid-column>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="EmployeeID" textAlign="Right" width="120"></e-grid-column>
</e-grid-columns>
</ejs-grid>
|
|
HomeController.cs
public ActionResult TelecomDataSource([FromBody]DataManagerRequest dataManager)
{
IEnumerable data = _context.Orders.ToList();
DataOperations operation = new DataOperations();
if (dataManager.Search != null && dataManager.Search.Count > 0)
{
data = operation.PerformSearching(data, dataManager.Search); //Search
}
if (dataManager.Sorted != null && dataManager.Sorted.Count > 0) //Sorting
{
data = operation.PerformSorting(data, dataManager.Sorted);
}
if (dataManager.Where != null && dataManager.Where.Count > 0)
{
data = operation.PerformFiltering(data, dataManager.Where, dataManager.Where[0].Operator); //Filtering
}
int count = data.Cast<Orders>().Count();
if (dataManager.Skip != 0)
{
data = operation.PerformSkip(data, dataManager.Skip);
}
if (dataManager.Take != 0)
{
data = operation.PerformTake(data, dataManager.Take);
}
return dataManager.RequiresCounts ? Json(new { result = data, count = count }) : Json(data);
}
public async Task<ActionResult> Insert([FromBody]CRUDModel<Orders> param)
{
_context.Orders.Add(param.Value);
await _context.SaveChangesAsync();
return Json(param.Value);
}
public async Task<ActionResult> Update([FromBody]CRUDModel<Orders> param)
{
_context.Orders.Update(param.Value);
await _context.SaveChangesAsync();
return Json(param.Value);
}
public async Task<ActionResult> Delete([FromBody]CRUDModel<Orders> param)
{
Orders value = _context.Orders.Where(e => e.OrderID == Int32.Parse(param.Key.ToString())).FirstOrDefault();
_context.Remove(value);
await _context.SaveChangesAsync();
return Json(value);
}
|
Hello, thanks for your help. I forgot to mention that I'm using .NET Core 5.0. I don´t really understand how but i managed to solve my problem.
Delete:
Not working:
public ActionResult Delete([FromBody]CRUDModel |
Working:
public async Task |
Editing:
Not working:
|
Working:
<ejs-grid id="Grid" enableStickyHeader="true" height="600" width="100%" allowPaging="true" allowSorting="true" allowResizing="true" toolbar="@(new List<string>() { "Search", "Add", "Edit", "Delete", "ExcelExport" ,"PdfExport"})" allowFiltering="true" allowSelection="true" allowExcelExport="true" allowPdfExport="true" toolbarClick="toolbarClick"> |
For delete, i just changed the way it search for the Id and the "int" var.
For edit, i just changed that TeamId column vible to "false". If i kept it "true", it would always return null value, even when i can´t even edit the id since it is Identity.