Frage

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.

War es hilfreich?

Lösung

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()
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top