[Urgent]Telerik Tag Helpers CRUD for GRID - not working

4 posts, 0 answers
  1. Simona
    Simona avatar
    5 posts
    Member since:
    Nov 2010

    Posted 25 Feb 2019 Link to this post

    Hello,

     

    I have the following grid and the Read method is working fine but when I try to delete or edit a record the button doesn't call the method from the controller.

    Can you please advise ?

    Here is the .cshtml

    <kendo-grid name="OverTime">
        <toolbar>
            <toolbar-button name="create" text="Add new Overtime"></toolbar-button>
        </toolbar>
        <columns>
            <column field="Id" title="ID" />
            <column field="RecordDate" format="{0:MM/dd/yyyy}" title="Record Date" />
            <column field="TimeFrom" title="Time From" />
            <column field="TimeTo" title="Time To" />
            <column field="NumberOfHours" title="Number of hours" />
            <column field="OvertimeReason" title="Overtime Reason" />
            <column>
                <commands>
                    <column-command text="delete" name="destroy"></column-command>
                    <column-command text="update" name="update"></column-command>
                </commands>
            </column>
        </columns>
        <datasource type="DataSourceTagHelperType.Ajax" page-size="20">
            <schema>
                <model id="Id">
                    <fields>
                        <field name="RecordDate" type="date"   />
                        <field name="TimeFrom" type="time" />
                        <field name="TimeTo" type="time" />
                        <field name="NumberOfHours" type="number" />
                        <field name="OvertimeReason" type="string" />
                    </fields>
                </model>
            </schema>
            <transport>
                <read url="@Url.Action("Read_Overtime","OverTimes",  new { id = ViewContext.RouteData.Values["Id"] })" />
                <destroy url="@Url.Action("Destroy_Overtime","OverTimes")" />
                <update url="@Url.Action("Update_Overtime","OverTimes")" />
            </transport>
        </datasource>
        <groupable enabled="true" />
        <sortable enabled="true" />
        <pageable button-count="5" refresh="true" />
        <filterable enabled="true" />
        <editable enabled="true" />
        <toolbar>
        </toolbar>
    </kendo-grid>

     

     

    Here is the update and delete method from the controller.

     

            [HttpPost]
            public ActionResult Destroy_Overtime ([DataSourceRequest]DataSourceRequest request, OverTimeViewModel overTime)
            {
                try
                {
                    OverTime over = _context.OverTime.Find(overTime.Id);
                    if (over == null)
                    {
                        return Json("Employee Not Found");
                    }

                    _context.OverTime.Remove(over);
                    _context.SaveChanges();
                    return Json(_context.OverTime.ToList());
                }
                catch (Exception ex)
                {
                    return Json(ex.Message);
                }
            }

            [HttpPost]
            public ActionResult Update_Overtime([DataSourceRequest]DataSourceRequest request, OverTime overTime)
            {

                try
                {
                    if(ModelState.IsValid)
                    {
                        
                        _context.Entry(overTime).State = EntityState.Modified;
                        _context.SaveChanges();
                        return Json(new[] { overTime }.ToDataSourceResult(request, ModelState));
                    }
                    else
                    {
                        return Json(_context.OverTime.ToList());
                    }
                }
                catch(Exception ex)
                {
                    return Json(ex.Message);
                }
            }

  2. Simona
    Simona avatar
    5 posts
    Member since:
    Nov 2010

    Posted 26 Feb 2019 Link to this post

    Can someone close this thread ? 

    I've solved the problem moving from tag helpers.

    Thanks

  3. Maxime
    Maxime avatar
    2 posts
    Member since:
    Mar 2020

    Posted 17 Mar 2020 Link to this post

    Hi,

    I have the same problem.

    Is there a demo with DataSourceTagHelperType.Ajax and all the CRUD functions? Include the code from the controller.

    Gr,

    Maxime

  4. Nikolay
    Admin
    Nikolay  avatar
    301 posts

    Posted 20 Mar 2020 Link to this post

    Hello Maxime,

    I have prepared a small ASP.NET Core project demonstrating how a Kendo UI Tag Helper Grid can enable inline editing with all CRUD operations and Ajax data binding. Please fint it attached.

    Let me know if anything further arises.

    Regards,
    Nikolay
    Progress Telerik

    Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Back to Top