I have a Core grid that manages the Sol objects.
<div
class
=
"col-sm-12"
>
@(Html.Kendo().Grid(Model)
.Name(
"mySolsGrid"
)
.Columns(columns =>
{
columns.Bound(c => c.Nom).Width(140);
columns.Bound(c => c.Code).Width(190);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);
})
.ToolBar(
toolbar => {
toolbar.Create();
toolbar.Excel();
}
)
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable(scr=>scr.Height(430))
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error(
"error_handler"
))
.Model(model => model.Id(p => p.Id))
.Create(update => update.Action(
"Sols_Create"
,
"Sols"
))
.Read(read => read.Action(
"Sols_Read"
,
"Sols"
))
.Update(update => update.Action(
"Sols_Update"
,
"Sols"
))
.Destroy(update => update.Action(
"Sols_Destroy"
,
"Sols"
))
)
)
</div>
This is my controller:
[AcceptVerbs(
"Post"
)]
public
async Task<ActionResult> Sols_CreateAsync([DataSourceRequest] DataSourceRequest request, SolDTO solDto)
{
SolDTO idOnly = solDto;
if
(solDto !=
null
&& ModelState.IsValid)
{
idOnly = await _solService.CreateAsync(solDto);
}
return
Json(
new
[] { idOnly }.ToDataSourceResult(request, ModelState));
}
this is my Service returning object:
public
async Task<SolDTO> CreateAsync(SolDTO solDto)
{
var sol = _mapper.Map<Sol>(solDto);
await _userService.SetCreatedByCurrentUserNowAsync(sol);
sol = await _repository.AddAsync(sol);
var dto = _mapper.Map<SolDTO>(sol);
return
dto;
}
I return here the ID that is not 0. However each time I add a new object (i click on update button) it calls the Create function one more time. First call once, second twice etc.
Does the Async method have something to do with that?