c# - Kendo UI Grid: update/save not working (_AntiForgeryToken not present) -
i have kendo grid displays contract attachments, has column 'status'. in column current status of attachment/contract displayed. when invoking 'edit' event combobox appears in cell available status options. after selecting status , clicking "update" button, following exception:
the required anti-forgery form field "__requestverificationtoken" not present.
i added @html.antiforgerytoken()
in view grid, , [validateantiforgerytoken]
annotation method.
what doing wrong here?
this grid:
@html.antiforgerytoken() @(html.kendo().grid<attachmentgridviewmodel>() .name("attachmenteditgrid") .htmlattributes(new { style = "height:auto;", @class = "kendohover" }) .columns(columns => { columns.bound(c => c.number).title(resources.number); columns.bound(c => c.consultant.firstname).title(resources.consultant); columns.bound(c => c.startdate).title(resources.startdate).format("{0:" + system.globalization.cultureinfo.currentculture.datetimeformat.shortdatepattern + "}"); columns.bound(c => c.enddate).title(resources.enddate).format("{0:" + system.globalization.cultureinfo.currentculture.datetimeformat.shortdatepattern + "}"); columns.bound(c => c.status).title(resources.status).editortemplatename("contractstatuseditor"); columns.command(command => { command.custom(resources.delete).text("<span class=\"glyphicon glyphicon-remove padding-deletebutton \"></span>" + resources.delete).click("onclickattachmentdelete").htmlattributes(new { @class = "btn btn-danger" }); command.edit().text(resources.edit).canceltext(resources.cancel); }).title(resources.action).width(200); }) .toolbar(toolbar => toolbar.template("<a class='k-button k-button-icontext' href='/fa/contractattachment/createcontractattachment?contractid=1'><span class='glyphicon glyphicon-plus'></span>" + resources.createattachment + "</a>")) //.scrollable() .pageable(pageable => pageable .refresh(true) .pagesizes(new list<object> { 3, 6, 12, resources.all }) .buttoncount(5)) // .sortable() .filterable(filterable => filterable .extra(true) .operators(operators => operators .forstring(str => str.clear() .contains(resources.contains) .startswith(resources.startswith) .endswith(resources.endswith) .isequalto(resources.isequalto) .isnotequalto(resources.isnotequalto) ))) .events(events => events .save("onsaveattachstatus") .edit("onattachedit") .databound("onattachdatabound") .cancel("oncancelediting") ) .editable(editable => editable.mode(grideditmode.inline)) .selectable(s => s.enabled(viewbag.permissions.returnvalue.faeditstatuscontractattachments)) .datasource(datasource => datasource .ajax() .serveroperation(true) .update(update => update.action("changestatus", "contractattachment").data("getvalues")) .read(read => read.action("readattachmentsgrid", "contract", new { id = id })) .pagesize(10) .model(model => { model.id(c => c.contractid); model.field(c => c.number).editable(false); model.field(c => c.consultant).editable(false); model.field(c => c.startdate).editable(false); model.field(c => c.enddate).editable(false); model.field(c => c.status).editable(true); }))/*end datasource*/
)
this actionmethod called save changes:
[httppost] [validateantiforgerytoken] [auth(permission.faeditstatuscontractattachments)] public jsonresult changestatus(int idattachment, string statuscontractattach) { var contractattach = _getcontractattachmentbyidqueryhandler.execute(idattachment).returnvalue; var contractattachstatus = (contractstatus)enum.parse(typeof(contractstatus), statuscontractattach); if (contractattach == null) { var json = new { result = "failed" }; return json(json, jsonrequestbehavior.allowget); } contractattach.statuscontractattachment = contractattachstatus; var result = _updatecontractattachmentcommandhandler.execute(new updatecontractattachmentcommand(contractattach)); if (result.haserror) { var json = new { result = "failed" }; return json(json, jsonrequestbehavior.allowget); } else { updatehistory(idattachment, contractattachstatus); var json = new { result = "success" }; return json(json, jsonrequestbehavior.allowget); } }
this jquery related grid :
//--------------------------attachments edit grid --------------------// //save event function onsaveattachstatus(e) { //post status data action method $.post('@url.action("changestatus", "contractattachment")', { contractid: e.model.id, status: e.model.statuscontract }).success(function(data) { showerrornotification('@resources.contractstatuschangedsuccessmessage', true); }); }; //kendo notification succesmessage function showerrornotification(message, success) { var notification = $("#staticnotification").data('kendonotification'); notification.show(message, success ? "success" : "error"); var container = $(notification.options.appendto); container.scrolltop(container[0].scrollheight); } function onclickattachmentdelete() { //custom delete function var idtodelete = $(this).closest('tr').data('attachid'); var attachnumber = $(this).closest('tr').data('number'); //initiates modal data $('#dialog-delete-attachnr').text(attachnumber); $("#dialog-delete-attach").modal(); $('#dialog-delete-attach').data('attachid', idtodelete); $('#dialog-delete-contract').data('attachnumber', attachtnumber); } //edit event function onattachedit(e) { var ddl = $("#status").data('kendodropdownlist'); var olddata = ddl.datasource._data; var signedaccountstatus = @((int) contractstatus.signedbyaccount); (var = 0; < olddata.length; i++) { if (ddl.selectedindex >= signedaccountstatus && parseint(olddata[i].value) < signedaccountstatus) { ddl.datasource.remove(olddata[i--]); } } console.log("edit ok"); } //resets grid data function resetgrid() { $("#attachmenteditgrid").data("kendogrid").datasource.read(); }; //returns data .update action function getvalues(e) { var id = e.data.attachid; var value = e.data("kendodropdownlist").value(); console.log(id, value); return { id, value }; } //hide edit button when status finished , hide delete when signed //when data loaded grid function onattachdatabound(e) { var attacheditgrid = $("#attachmenteditgrid").data("kendogrid"); var attacheditgriddata = attacheditgrid.datasource.view(); //loop through rows (var = 0; < attacheditgriddata.length; i++){ var row = attacheditgrid.table.find("tr[data-uid='" + attacheditgriddata[i].uid + "']"); var statuscontractattach = attacheditgriddata[i].status; //hide delete when signed if (statuscontractattach >= @((int) contractstatus.signedbyaccount)){ row.find('.k-grid-delete').hide(); } //hide edit when contract finished if (statuscontractattach == @((int)contractstatus.finished)){ row.find(".k-grid-edit").hide(); } } }; //cancel edit function oncancelediting(e) { resetgrid(); onattachdatabound(); }
Comments
Post a Comment