1

sorry for my bad english, but let's to the problem.

i am trying to do a POST into the action complete of the controller occurrence, but the action don't receive the POST and the javascript console returns this error 500 Internal Server Error

This is my Ajax.actionlink()

@Ajax.ActionLink("Complete", "Complete", "Occurrence", new { id = Model.Id }, new AjaxOptions { HttpMethod = "POST" }) 

And this is my action Complete into the controller Occurrence

 [HttpPost] [ValidateAntiForgeryToken] public ActionResult Complete(int id) { return new HttpStatusCodeResult(200); } 

Someone has passed for the same situation? Thanks for the attention!

1 Answer 1

2

Your action is decorated with the [ValidateAntiForgeryToken] meaning that it will expect that the anti forgery token gets sent into the POST request payload. This isn't the case. In your request you are only sending some id (new { id = Model.Id }).

Once possible workaround is to use an Ajax.BeginForm instead which will contain the anti forgery token:

@using (Ajax.BeginForm("Complete", "Occurrence", new { id = Model.Id }, new AjaxOptions { HttpMethod = "POST" })) { @Html.AntiForgeryToken() <button type="submit">Complete</button> } 

The Html.AntiForgeryToken() will generate a hidden field containing the required anti forgery token that will be sent along with the AJAX request to the server.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much, now i know what is the problem, was almost crazy with this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.