문제

I have three controllers but Controller1 inherited from Controller2 and Controller2 inherited of the Controller3.

for example

public class Controller1 : Controller
{
    [HttpPost]
    [ValidateAntiForgeryToken()]
    public virtual ActionResult Create(MyClass test)
    {
...

public class Controller2 : Controller1
{
...

public class Controller3 : Controller2
{
    [HttpPost]
    [ValidateAntiForgeryToken()]
    public override ActionResult Create(MyClass test)
...

also in View add

@Html.AntiForgeryToken()

when have one control and no inherited good work but when use inherit and override method the ValidateAntiForgeryToken get error.

validationAntiforgeryToken is not valid and get Error:

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

[HttpAntiForgeryException (0x80004005): The required anti-forgery form field "__RequestVerificationToken" is not present.]

...

thanks.

도움이 되었습니까?

해결책

Your problem is not with your Controller-hierarchy, it's because you don't have an AntiForgeryToken in the request (as the error says).

To do so, add the following to your view (inside the form) that posts to the Controller:

@Html.AntiForgeryToken()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top