We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Example of CRUD operations with SQL server in ASP.NET Core Razor environment

Hi,
I am using a dataGrid component in a ASP.NET Core Razor project to interact with a SQL database but cannot get the CRUD operations to work.
The routine defined in the removeURL property does not seem to be called at all.
Can you please tell me what is wrong with the code below? Thank you.

Index.cshtml
@page
...
@Html.AntiForgeryToken()

<ejs-grid id="GridPaikat"
          allowpaging="true"
          load="onLoad"
          toolbar="@(new List<string>() {"Add", "Edit", "Update", "Delete", "Search", "Cancel" })">
    <e-data-manager json="@Model.Havaintopaikka.ToArray()"
                    removeUrl="Remove"
                    adaptor="RemoteSaveAdaptor">
    </e-data-manager>
    <e-grid-editSettings allowDeleting="true"></e-grid-editSettings>
    <e-grid-columns>
        <e-grid-column field="Id" headerText="Id" width="50" isPrimaryKey="true"></e-grid-column>
        <e-grid-column field="Alue" headerText="Alue"></e-grid-column>
        <e-grid-column field="Lyhenne" headerText="Lyhenne"></e-grid-column>
        <e-grid-column field="Paikka" headerText="Paikka"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

<script>
    function onLoad() {
        this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];
    }
</script>

Index.cshtml.cs
...
        public JsonResult OnPostRemove([FromBody]CRUDModel<Havaintopaikka> value)
        {
            _context.Havaintopaikat.Remove(value.Value);
            return new JsonResult(value);
        }

4 Replies

RC Roger Criebaum August 20, 2019 07:35 PM UTC

I have the same situation. I am trying to edit a DataTable retrieved from SQL Server using a DataGrid (any edit mode, but mostly either inline or form). I can get the data relatively simply. But after I edit, the routine called is wanting an IEnumerable and that's as far as I get. It would be nice to have a good example of how to do this, as the documentation doesn't go into much detail or explanation.


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 21, 2019 10:42 AM UTC

Hi Customers,  
 
We have prepared a sample with the CRUD Action in the Razor Page that can be downloaded from the following location.  
 
 
Regards,  
Seeni Sakthi Kumar S. 



RM Rui Mendes December 3, 2019 08:35 AM UTC

Hi,

Disclaimer: new user here
´
Using the provided example https://www.syncfusion.com/downloads/support/forum/146787/ze/EJ2Grid334825853.zip  (which works well up-front) and updating to the newest EJ2.Asp:Net.Core versions 17.3.x breaks the solution with a "Uncaught SyntaxError: Unexpected token 'var'" error
 ],
  "dataSource": var DataManager=new ejs.data.DataManager({
  "adaptor": new ejs.data.RemoteSaveAdaptor(),
  "removeUrl": "/Index?handler=Remove",
  "json": ejs.data.DataUtil.parse.isJson([

I'm using EJ2 community license and am getting the same error: basically in my testings I find the Grid works well (e.g. fed from a list) until I start to adopt  <e-data-manager> tag (for CRUD implementation).

Any hints on what could be the cause?



SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team December 4, 2019 06:19 AM UTC

Hi Rui, 
 
Query: newest EJ2.Asp:Net.Core versions 17.3.x breaks the solution with a "Uncaught SyntaxError: Unexpected token 'var'" error 
 
We can reproduce the reported problem and we have already fixed the reported problem at our end. You can resolve the reported problem by upgrading NuGet version to 17.3.0.31. For your reference, we have attached the sample with NuGet version 17.3.0.31. 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Seeni Sakthi Kumar S 


Loader.
Live Chat Icon For mobile
Up arrow icon