This is a migrated thread and some comments may be shown as answers.

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

3 Answers 311 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simona
Top achievements
Rank 1
Simona asked on 25 Feb 2019, 07:37 AM

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

3 Answers, 1 is accepted

Sort by
0
Simona
Top achievements
Rank 1
answered on 26 Feb 2019, 06:59 AM

Can someone close this thread ? 

I've solved the problem moving from tag helpers.

Thanks

0
MVDH
Top achievements
Rank 1
answered on 17 Mar 2020, 08:47 AM

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

0
Nikolay
Telerik team
answered on 20 Mar 2020, 07:08 AM

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.
Tags
Grid
Asked by
Simona
Top achievements
Rank 1
Answers by
Simona
Top achievements
Rank 1
MVDH
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or