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

Grid won't update or delete

5 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 15 May 2014, 09:51 PM

Hi. I'm trying to use the grid to display some data which a user is supposed to change. The problem is that so far I have been unsuccessful in making the grid update/edit or delete, nothing happens when I click the "Save" button. Or when I press enter. It just doesn't hit the controller when I set a break point. If I create or read, it works fine.

To create the project I did the following

  1. Started a new MVC project though the basic asp.net web wizard
  2. Converted to telerik application to UI for ASP.net MVC
  3. Updated all scripts to their newest version
  4. Enabled entity framework migrations with automatic migrations.

My versions are:
* jQuery 1.10.2
* KendoUI 2014.1.415
* Bootstrap 3.0.0.0
* MVC 5.1.0.0

ManageWorkPlacements.cshtml

01.@(Html.Kendo().Grid<WorkPlacementModel>()
02.            .Name("Grid")
03.            .Columns(columns =>
04.            {
05.                columns.Bound(p => p.Name);
06.                columns.Bound(p => p.CvrNumber);
07.                columns.Command(command => command.Destroy()).Width(110);
08.            })
09.            .ToolBar(toolbar =>
10.            {
11.                toolbar.Create();
12.                toolbar.Save();
13.            })
14.            .Editable(editable => editable.Mode(GridEditMode.InCell))
15.            .Pageable()
16.            .Navigatable()
17.            .Sortable()
18.            .Scrollable()
19.            .DataSource(dataSource => dataSource
20.                .Ajax()
21.                .Batch(true)
22.                .PageSize(20)
23.                .ServerOperation(false)
24.                .Events(events => events.Error("error_handler"))
25.                .Model(model => model.Id(p => p.Id))
26.                .Create("WorkPlacement_Create", "WorkPlacement")
27.                .Read("WorkPlacement_Read", "WorkPlacement")
28.                .Update("WorkPlacement_Update", "WorkPlacement")
29.                .Destroy("WorkPlacement_Destroy", "WorkPlacement")
30.            )
31.        )
32.        <script type="text/javascript">
33.            function error_handler(e) {
34.                if (e.errors) {
35.                    var message = "Errors:\n";
36.                    $.each(e.errors, function (key, value) {
37.                        if ('errors' in value) {
38.                            $.each(value.errors, function () {
39.                                message += this + "\n";
40.                            });
41.                        }
42.                    });
43.                    alert(message);
44.                }
45.            }
46.        </script>

WorkPlacementController.cs
01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Web;
05.using System.Web.Mvc;
06.using Kendo.Mvc.Extensions;
07.using Kendo.Mvc.UI;
08.using RegistreringMVC.Migrations;
09.using RegistreringMVC.Models;
10.using RegistreringMVC.Services;
11. 
12.namespace RegistreringMVC.Controllers
13.{
14.  public class WorkPlacementController : Controller
15.  {
16.    private WorkPlaceService workPlacementService;
17. 
18.    public WorkPlacementController()
19.    {
20.      workPlacementService = new WorkPlaceService(new RegistreringEntities());
21.    }
22. 
23.    public ActionResult WorkPlacement_Read([DataSourceRequest] DataSourceRequest request)
24.    {
25.      return Json(workPlacementService.Read().ToDataSourceResult(request));
26.    }
27. 
28.    [AcceptVerbs(HttpVerbs.Post)]
29.    public ActionResult WorkPlacement_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<WorkPlacementModel> workPlacements)
30.    {
31.      var results = new List<WorkPlacementModel>();
32. 
33.      if (workPlacements != null && ModelState.IsValid)
34.      {
35.        foreach (var workPlacement in workPlacements)
36.        {
37.          workPlacementService.Create(workPlacement);
38.        }
39.      }
40. 
41.      return Json(results.ToDataSourceResult(request, ModelState));
42.    }
43. 
44.    [AcceptVerbs(HttpVerbs.Post)]
45.    public ActionResult WorkPlacement_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<WorkPlacementModel> workPlacements)
46.    {
47.      if (workPlacements != null && ModelState.IsValid)
48.      {
49.        foreach (var workPlacement in workPlacements)
50.        {
51.          workPlacementService.Update(workPlacement);
52.        }
53.      }
54. 
55.      return Json(workPlacements.ToDataSourceResult(request, ModelState));
56.    }
57. 
58.    [AcceptVerbs(HttpVerbs.Post)]
59.    public ActionResult WorkPlacement_Destroy([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<WorkPlacementModel> workPlacements)
60.    {
61.      if (workPlacements.Any())
62.      {
63.        foreach (var workPlacement in workPlacements)
64.        {
65.          workPlacementService.Destroy(workPlacement);
66.        }
67.      }
68. 
69.      return Json(workPlacements.ToDataSourceResult(request, ModelState));
70.    }
71.  }
72.}

The code is taken almost directly from the offline samle (just to make it work). But still it doesn't. I tried remaking the whole project, in case I had changed something without thinking about it. But this does not help either. If you require any further code, please reply and i'll add it.

Thank you
Daniel

5 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 19 May 2014, 02:06 PM
Hello Daniel,

The Grid configuration looks fine, so I am not exactly sure what is causing this. Are there any errors in the browser console or AJAX requests with a status other than 200? Also, is the kendo.aspnetmvc.min.js file included? In case the file is included and there are no errors I would ask you to provide a runnable copy of the project so we can replicate the issue locally and advise you further.

Regards,
Alexander Popov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Daniel
Top achievements
Rank 1
answered on 27 May 2014, 07:58 PM
Hi Alexander,

The console actually did show something as I tried to update and delete (see attached file).

Regards
Daniel
0
Alexander Popov
Telerik team
answered on 29 May 2014, 09:15 AM
Hi Daniel,

I reviewed the attached screenshot, however it does not reveal what exactly is causing the error. I would recommend examining the requests responses, where the server exception will be displayed. 

Regards,
Alexander Popov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Nasir
Top achievements
Rank 1
answered on 17 Apr 2017, 06:56 AM

Good Morning Sir,

Sir I am having the same problem. I checked the console and network tab as well in the Browser Inspect Element but everything is fine. No error being shown there.

And the kendo.aspnetmvc.min.js is also included but again the update button is not hitting the Controller ActionListener.

Can you please help me what's the problem sir.

Thanks

0
Boyan Dimitrov
Telerik team
answered on 18 Apr 2017, 02:24 PM
Hello,

Could you please clarify whether there is a request to the server at least? The best way to investigate the problem would be open a support ticket and attached a sample runnable copy of your project. 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Daniel
Top achievements
Rank 1
Nasir
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or