1

I am trying to implement antiforgery token for jqgrid, below is what I am trying to do

    var token =  $('[name= "__RequestVerificationToken"]').val()

 $("#gridname").jqGrid('setGridParam',{ postData:{__RequestVerificationToken:token,aID : @ViewBag.AID}});     

 $("#gridname").trigger("reloadGrid");

I have also placed the @Html.AntiForgeryToken(); in the body of the page. Using debugger I can see that a token is generated too but I am getting

Exception Details: System.Web.Mvc.HttpAntiForgeryException: A required anti-forgery token was not supplied or was invalid.

in the controller, I have placed [ValidateAntiForgeryToken] and its not hitting the same. Is there any solution to this. Can Antiforgery token be applied in jqgrid?

2
  • Did you tried sending the forgery token as a header? Dec 30, 2014 at 3:37
  • Try passing the value directly in postData: __RequestVerificationToken:$('[name= "__RequestVerificationToken"]').val() Or you try passing it in extra param of jqGrid: extraparam : { __RequestVerificationToken: $('input[name=__RequestVerificationToken]').val()} } Dec 30, 2014 at 6:13

1 Answer 1

1

You have to add request forgery token in your HEADERS as Nacho suggested in comments.

var headers = {};

headers['__RequestVerificationToken'] = $('[name= "__RequestVerificationToken"]').val();

 $("#gridname").jqGrid('setGridParam',{ headers: headers, postData:{aID : @ViewBag.AID}});     

Hope this helps

1
  • Thanks for the suggestion. I tried passing in headers like you mentioned but I am still getting System.Web.Mvc.HttpAntiForgeryException: A required anti-forgery token was not supplied or was invalid. Is there anything else you see I can try.
    – shaan N
    Dec 30, 2014 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.