0

I have a web page with a partial view. The partial view contains buttons to update the items. Normally updating works fine. i.e. when the partial view is initially loaded as part of the page creation.

However I am now using AJAX to update the partial view. When I then click on the Ajax generated button within the partial view and try to update the item I get the error: The anti-forgery token could not be decrypted...

Looking at the data being sent, I noticed that the initially rendered buttons are sending a Set-Cookie header. and the updated AJAX generated buttons are not.

Looking at the generated HTML everything looks identical. But clearly the AJAX generated content is being treated differently to when it's pre-rendered

jimmy
  • 709
  • 3
  • 15
  • 33
  • See this answer http://stackoverflow.com/questions/19788916/how-to-make-ajax-request-with-anti-forgery-token-in-mvc – JB06 Sep 03 '15 at 13:22
  • I've tried that, but it hasn't helped. Also doesn't explain why a button generated via AJAX, work differently to a pre-rendered button. Despite them both having the same HTML. – jimmy Sep 03 '15 at 14:03
  • make sure you dont have more than one anti-forgery token on your page. particularly in your form – JamieD77 Sep 03 '15 at 14:08
  • 1
    adding your view and partial view code would be helpful – JamieD77 Sep 03 '15 at 14:09
  • Thanks for your help. Turns out I missed a JavaScript lib when I was searching. it was using .on() on the original element which was being overwritten. It was then not triggering for the new buttons. set it to the body and everything is working now. – jimmy Sep 03 '15 at 14:58

0 Answers0