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