Grid Updates but does not insert or delete

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.


Attachment: PARECA21.API_d652371f.rar

3 Replies 1 reply marked as answer

RR Rajapandi Ravi Syncfusion Team November 2, 2021 01:11 PM UTC

Hi Javier, 

We have checked your shared sample and we are not able to run at our end. Based on your application scenario we have prepared a Sample of URL adaptor Grid with Entity framework. Please refer the below code example and sample for more information. 

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); 
        } 
 
 


If you still face the problem, please share the below details that will be helpful for us to provide better solution. 

1)                   Please share the video demonstration of the problem. 

2)                   Please replicate the issue with our above attached sample or share any issue reproducible sample that would be helpful for us to validate the application. 


Rajapandi R 



JA Javier November 5, 2021 05:32 PM UTC

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 value)
{
Team order = _context.Teams.Where(c => c.Id == (int)value.Key).FirstOrDefault();
_context.Teams.Remove(order);
_context.SaveChanges();
return Json(order);
}


Working:

        public async Task Delete([FromBody]CRUDModel value)
{
Team order = _context.Teams.Where(c => c.TeamId == Int32.Parse(value.Key.ToString())).FirstOrDefault();
_context.Teams.Remove(order);
await _context.SaveChangesAsync();
return Json(order);
}


Editing:

Not 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">
    <e-data-manager url="/SfTeams/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/SfTeams/Insert" updateUrl="/SfTeams/Update" removeUrl="/SfTeams/Delete"></e-data-manager>
    <e-grid-filterSettings type="CheckBox"></e-grid-filterSettings>
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" showConfirmDialog="true" showDeleteConfirmDialog="true"></e-grid-editSettings>
    <e-grid-selectionsettings type="Single"></e-grid-selectionsettings>
    <e-grid-pagesettings pageSize="50"></e-grid-pagesettings>
    <e-grid-columns>
        <e-grid-column field="TeamId" headerText="TeamId" isPrimaryKey="true" isIdentity="true></e-grid-column>
        <e-grid-column field="Name" headerText="Nombre"></e-grid-column>
        <e-grid-column field="ShortName" headerText="Abreviatura"></e-grid-column>
        <e-grid-column field="RaffleNumber" headerText="Número de Sorteo"></e-grid-column>
        <e-grid-column field="TotalPoints" headerText="Puntuación Total"></e-grid-column>
    </e-grid-columns>
</ejs-grid>


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">
    <e-data-manager url="/SfTeams/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/SfTeams/Insert" updateUrl="/SfTeams/Update" removeUrl="/SfTeams/Delete"></e-data-manager>
    <e-grid-filterSettings type="CheckBox"></e-grid-filterSettings>
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" showConfirmDialog="true" showDeleteConfirmDialog="true"></e-grid-editSettings>
    <e-grid-selectionsettings type="Single"></e-grid-selectionsettings>
    <e-grid-pagesettings pageSize="50"></e-grid-pagesettings>
    <e-grid-columns>
        <e-grid-column field="TeamId" headerText="TeamId" isPrimaryKey="true" isIdentity="true" visible="false"></e-grid-column>
        <e-grid-column field="Name" headerText="Nombre"></e-grid-column>
        <e-grid-column field="ShortName" headerText="Abreviatura"></e-grid-column>
        <e-grid-column field="RaffleNumber" headerText="Número de Sorteo"></e-grid-column>
        <e-grid-column field="TotalPoints" headerText="Puntuación Total"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

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.


Marked as answer

RR Rajapandi Ravi Syncfusion Team November 8, 2021 11:46 AM UTC

Hi Javier, 

We are happy to hear that you have found the solution at your end. 

From your update we could see that you are performing Grid CRUD Operations in ASP.NET CORE 5. Based on your query we have prepared a sample in ASP.NET CORE 5.  The Crud was working fine in ASP.NET CORE 5. Please refer the below sample for more information. 


Note: Before running the above sample, please change the path according to your folder in app.setting.json file.  

The below article explains How to Build CRUD Operations Using ASP.NET Core 5.0. Please refer the below documentation for more information. 


Regards, 
Rajapandi R

Loader.
Up arrow icon