I am trying to show the error returned by the server side ASP.Net core code. i have added a breakpoint in the actionFailure javascript method but the breakpoint is not hit. What am i missing?
public async Task<JsonResult> OnPostInsert([FromBody]SyncfusionControlCrudModel<Keyword> syncfusionControlCrudModel)
{
var keywordText = syncfusionControlCrudModel?.value?.Value?.ToLowerInvariant();
if (string.IsNullOrEmpty(keywordText) || keywordText.Length<4)
{
ModelState.AddModelError(string.Empty, "The keyword text needs to be at least 3 characters");
return null;
}
var identityUser = await UserManager.GetUserAsync(User);
var keyword = new Keyword()
{
UserId = identityUser.Id,
Value = keywordText
};
ApplicationDbContext.Keywords.Add(keyword);
await ApplicationDbContext.SaveChangesAsync();
return new JsonResult(syncfusionControlCrudModel.value);
}
<div class="col-md-12">
@Html.AntiForgeryToken()
<div class="form-group">
<label class="form-control-label">New keywords</label>
<ejs-grid id="GridNewKeywords" allowPaging="true" load="onLoad" actionFailure="actionFailure"
actionbegin="actionbegin" toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel"})">
<e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true" />
<e-data-manager url="/Settings?handler=DataSource" insertUrl="/Settings?handler=Insert"
updateUrl="/Settings?handler=Update" removeUrl="/Settings?handler=Delete"
adaptor="UrlAdaptor" />
<e-grid-pageSettings pageCount="5" pageSize="5" />
<e-grid-columns>
<e-grid-column field="KeywordId" headerText="Id" visible="false" isPrimaryKey="true" width="0" allowEditing="false" />
<e-grid-column field="UserId" headerText="UserId" visible="false" isPrimaryKey="true" width="0" allowEditing="false" />
<e-grid-column field="Value" headerText="Keyword" validationRules="@(new { required=true})" />
</e-grid-columns>
</ejs-grid>
</div>
</div>
<script>
function onLoad()
{
this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];
}
function actionFailure(args)
{
var span = document.createElement('span');
this.element.parentNode.insertBefore(span, this.element);
span.style.color = '#FF0000'
span.innerHTML = 'Server exception: 404 Not found';
}
function actionbegin(args)
{
console.log(args);
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
if (args.requestType == 'delete')
{
grid.dataSource.dataSource.headers = [];
grid.dataSource.dataSource.headers.push(
{
'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val(),
"KeywordId": args.data[0].KeywordId,
"UserId": args.data[0].UserId
});
}
}
</script>