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

ListView DataSource calling Create Action Multiple times

1 Answer 219 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Scott Singleton
Top achievements
Rank 1
Scott Singleton asked on 03 Feb 2017, 08:00 PM

So we've read the docs; done all the appropriate searching; yet cannot keep the listview from repeating calls to the create service.

According to the docs the listview datasource expects the item that was added to be returned.  Here is our server side controller method:

 

[HttpPost]
public ActionResult CreateMultiSelectItem([DataSourceRequest] DataSourceRequest request, long questionId, SurveyQuestionMultiSelectItem item)
{
    if (item != null && ModelState.IsValid)
    {
        var vm = new SurveyQuestionMultiSelectViewModel(_surveyQuestionService.GetById(questionId));
        vm.SurveyQuestionDetails.Items.Add(item);
        vm.UpdateRootSurveyQuestion(_surveyQuestionService);
    }
    return Json(new[] {item}.ToDataSourceResult(request, ModelState));
}

 

as you can see we are returning the exact item being created.

 

The Datasource setup for the listview is as such:

<div class="demo-section k-content wide">
    <a class="k-button k-button-icontext k-add-button" href="#"><span class="k-icon k-add"></span>Add new record</a>
    @(Html.Kendo().ListView<LMI.QMIMS.Business.SurveyQuestions.SurveyQuestionMultiSelectItem>()
          .Name("listView")
          .TagName("div")
          .ClientTemplateId("template")
          .DataSource(source=>source
              .Model(model=>
                    {
                        model.Id(p=>p.Id);
                        model.Field(p => p.Id).DefaultValue(Guid.NewGuid());
                    }
              )
              .Create(create=>create.Action("CreateMultiSelectItem","SurveyQuestion", new { questionId = Model.SurveyQuestionId }))
              .Read(read=>read.Action("ReadMultiSelectItem","SurveyQuestion",new { questionId = Model.SurveyQuestionId}))
              .Update(update=>update.Action("UpdateMultiSelectItem", "SurveyQuestion", new { questionId = Model.SurveyQuestionId }))
              .Destroy(destroy=>destroy.Action("DeleteMultiSelectItem", "SurveyQuestion",new { questionId = Model.SurveyQuestionId } ))
              .Events(events=>events.Error("onDataSourceError"))
          )
          .Pageable()
          .Editable()
          )
</div>

 

 

So am I missing something totally obvious?  I do this sort of behavior in the Grid control all day long without this issue.

 

-Scott Singleton

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 07 Feb 2017, 04:42 PM
Hi Scott,

It looks to make a single request in our online demo here:
http://demos.telerik.com/aspnet-mvc/listview/editing
The same happens if I run the code of the demo locally. So I am not sure why it behaves differently in your page.

You may want to profile the executed JavaScript after the first response is received and see what function is exactly causing the second request.

Regards,
Vasil
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
ListView
Asked by
Scott Singleton
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or