For validating anti forgery token with in ajax call, you need to do a slight change.
Below is my Index page.
<form id="__AjaxAntiForgeryForm" action="#" method="post">
@Html.AntiForgeryToken()
<button onclick="test()">
ClickMe
</button>
</form>
Now keeping your Javascript code with slight modification as below.
<script>
function test() {
AddAntiForgeryToken = function (data) {
data.__RequestVerificationToken = $('#__AjaxAntiForgeryForm input[name=__RequestVerificationToken]').val();
return data;
};
var producer = "test";
var json = AddAntiForgeryToken( { "EmailId": producer });
$.ajax({
type: "POST",
url: "/Employee/ForgotPassword/",
data: json,
dataType: "json",
success: function (data) {
alert("okay");
},
error: function (data) {
alert("not okay");
}
});
}
</script>
Basically here you have to pass the data with token. The main changes on data parameter.
And below is the action method in my Employee controller instead of Account controller.
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ForgotPassword(string EmailId)
{
return View();
}
Hope this helps.
I am able to call action method by doing above changes on your code.