Solution :
If you have a [ValidateAntiForgeryToken]
attribute before the action. Then you also should add a @Html.AntiForgeryToken()
in the form.
OR
In my case, I had below code in my web.config:
<httpCookies requireSSL="true" />
But my project was set to not use the SSL. So commenting out that line or setting up a project to always use the SSL solved it.
OR
Please make sure that in your controller that you have the http attribute like:
[HttpPost]
Also add a attribute in a controller:
[ValidateAntiForgeryToken]
In your form on the view you have to write as below:
@Html.AntiForgeryToken();
I had the Html.AntiForgeryToken(); without a @ sign while it was in the code block, it didn't give the error in Razor but did give at runtime. So make sure you look at the @ sign of @Html.Ant.. if it is missing there or not
OR
If anyone is experiencing a error for the same reason why I experience it, then here's my solution:
If you had a Html.AntiForgeryToken();
Then change it to @Html.AntiForgeryToken()