I added a toolbar to my grid, with new, save and cancel buttons. On my page, I configure the datasource to use the save routine in my controller. However, any breakpoints set in my Save (update) routine are never hit, even after editing and saving the grid. Is there an event I should be capturing? Like all of my issues, this is after following an example on the Telerik site. My read method is working perfectly.
Index.cshtml
<form class="form-inline">
<div class="form-group mb-2">
<label for="SievePack" class="sr-only">Choose a Sieve Set</label>
<kendo-grid name="SievePack"
detail-template-id="template"
navigatable="true">
<columns>
<column field="SieveSetId" title="Set ID" />
<column field="SieveSetName" title="Name" />
</columns>
<toolbar>
<toolbar-button name="create" ></toolbar-button>
<toolbar-button name="save"></toolbar-button>
<toolbar-button name="cancel"></toolbar-button>
</toolbar>
<datasource page="0" type="DataSourceTagHelperType.Custom" custom-type="odata" page-size="6" batch="true" >
<schema data="Data" total="Total" errors="Errors">
</schema>
<transport>
<read url="@Url.Action("ReadSieveSets", "SievePack")" datatype="json" />
<update url="@Url.Action("Sievesets_Update", "SievePack")" />
<create url="@Url.Action("Sievesets_Create", "SievePack")" />
</transport>
</datasource>
<editable mode="incell" />
</kendo-grid>
</div>
</form>
and the controller:
[HttpPost]
public ActionResult Sievesets_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<SieveSet> sets)
{
// Will keep the updated entities here. Used to return the result later.
var entities = new List<SieveSet>();
if (ModelState.IsValid)
{
using (_context)
{
foreach (var set in sets)
{
// Create a new Product entity and set its properties from the posted ProductViewModel.
var entity = new SieveSet
{
SieveSetName = set.SieveSetName,
SieveSetId = set.SieveSetId
};
// Store the entity for later use.
entities.Add(entity);
// Attach the entity.
_context.Attach(entity);
// Change its state to Modified so Entity Framework can update the existing product instead of creating a new one.
_context.Entry(entity).State = EntityState.Modified;
}
// Update the entities in the database.
_context.SaveChanges();
}
}
// Return the updated entities. Also return any validation errors.
return Json(entities.ToDataSourceResult(request, ModelState, set => new SieveSet
{
SieveSetName = set.SieveSetName,
SieveSetId = set.SieveSetId
}));
}
(note - I had been using type = Ajax. This is pasted from my current attempt using custom data, based off an article I read here)