include antiforgerytoken in ajax post ASP.NET MVC

后端 未结 11 2363
感动是毒
感动是毒 2020-11-22 14:00

I am having trouble with the AntiForgeryToken with ajax. I\'m using ASP.NET MVC 3. I tried the solution in jQuery Ajax calls and the Html.AntiForgeryToken(). Using that solu

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 14:42

    I know this is an old question. But I will add my answer anyway, might help someone like me.

    If you dont want to process the result from the controller's post action, like calling the LoggOff method of Accounts controller, you could do as the following version of @DarinDimitrov 's answer:

    @using (Html.BeginForm("LoggOff", "Accounts", FormMethod.Post, new { id = "__AjaxAntiForgeryForm" }))
    {
        @Html.AntiForgeryToken()
    }
    
    
    Submit
    
    
    

提交回复
热议问题