This project is read-only.

how to add antiforgery token to ajax?

Topics: Customizing Orchard, Writing modules
May 26, 2015 at 12:28 AM
I am working on the commerce module following the steps from IDeliverable blog

I am having difficulties making ajax call to work. I got the following message:

The required anti-forgery form field "__RequestVerificationToken" is not present.

apparently, the blog was made before this antiforgery feature and the author did update the articles partially.

I tried to find solutions online for the entire day and couldn't find anything that works for me. Therefore, I am here asking for help. Can anyone who had the same issues help?

May 26, 2015 at 1:20 AM
All right. this sounds stupid. I found the solution right after i posted this question. my bad. So, what I did to resolve it is that I changed the model structure passed via AJAX.

According to the tutorial. The AJAX call was passing an array object and apparently, I can't attach the forgery token onto the array object. So i created a wrapper object that takes in the array object and construct my ajax data the same way. Then I took out the content type as directed by other posts and that works!!
May 28, 2015 at 1:06 PM
Hi I post the solution here
The easiest way to pass objects to ajax controller and bind them to actual model