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

Ajax code not called correctly

4 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amanda
Top achievements
Rank 1
Amanda asked on 08 Jul 2013, 11:39 PM
I'm trying to add a new record using GridEditMode.PopUp, but my methods are called incorrectly and sometimes not called at all.
My grid is declared like this:
@(Html.Kendo().Grid<DigiBob.AppServices.ViewModels.Governance.Duties.AdhocTaskViewModel>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.ShortDescription).Width(50);
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
    })
    .ToolBar(toolbar =>
    {
        toolbar.Create();
    })
    .Editable(ed=>ed.Mode(GridEditMode.PopUp).TemplateName("AdhocTask"))
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()  
    .DataSource(dataSource => dataSource   
        .Ajax()
        .PageSize(20)
        .Events(events => events.Error("error_handler"))
        .Model(model => model.Id(c => c.ID))
        .Create(update => update.Action("CreateAdhocTask", "Home"))
        .Read(read => read.Action("GetAllAdhocTasks", "Home"))
        .Update(update => update.Action("UpdateAdhocTask", "Home"))   
        .Destroy(update => update.Action("DestroyAdhocTask", "Home"))
        )   
)
With the Create method like this:
[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CreateAdhocTask([DataSourceRequest] DataSourceRequest request, AdhocTaskViewModel item)
        {
            if (item != null && ModelState.IsValid)
            {
                _adhocTaskRepository = new AdhocTaskRepository(_context);
                AdhocTask target = new AdhocTask();
                target.ShortDescription = item.ShortDescription;
                _adhocTaskRepository.Insert(target);
                _adhocTaskRepository.Save();
                item.ID = target.ID;
            }
 
            return Json(new[] { item }.ToDataSourceResult(request, ModelState));
        }
When I try to debug it, the code in the CreateAdhocTask method is not called consequtively.  Instead the debugger jumps up and down between the lines until it finally reaches the last }
Debugging it again makes it jump around again, but in a different order.  It seems to have a mind of it's own.  It's working fine for the Read method.

More confusing is that it also calls the CreateAdhocTask method for the Update method, although a different method is supposed to be called there.
Also, the DestroyAdhocTask is completely ignored.

What would cause this?

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 11 Jul 2013, 05:53 AM
Hi Amanda,

 Most probably the condition in the if statement is never met - either item is null or ModelState is not valid. This is why the debugger doesn't step in the if block.
 You can try breaking at the if statement and inspecting the item argument and ModelState property. 

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Amanda
Top achievements
Rank 1
answered on 11 Jul 2013, 06:55 AM
Hi Atanas,
The condition is met.  The debugger then goes to the next line, then back to the if.  Then onwards again just to jump to another line at another time.  This doesn't make any sense
0
Amanda
Top achievements
Rank 1
answered on 11 Jul 2013, 06:58 AM
Another problem is that the wrong methods are called, e.g. Insert for update.

And, the delete method never gets called
0
Atanas Korchev
Telerik team
answered on 13 Jul 2013, 07:17 AM
Hi Amanda,

We would be able to provide further instructions if we reproduce the erroneous behavior your are describing. There is a chance that the custom popup editor template is affecting the grid somehow. We cannot tell until we see your complete project.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Amanda
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Amanda
Top achievements
Rank 1
Share this question
or