Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

How to post to block controller action?

$
0
0

I have the following form being rendered from within a block.

@using (Html.BeginForm("Logout", null, new { language = ContentLanguage.PreferredCulture.Name }, FormMethod.Post)) {
    @Html.AntiForgeryToken();<button type="submit">Log Out</button>
}

Here's the controller:

public class HeaderBlockController : BlockController<HeaderBlock>
{
    [HttpGet]
    public override ActionResult Index(HeaderBlock currentBlock)
    {
        var model = new HeaderBlockViewModel(currentBlock);
        return PartialView("Blocks/HeaderBlock", model);
    }
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Logout()
    {
        // Log user out
        // Redirect
        return Redirect("/");  
    }
}

When I submit the form, the page 404s and does not actually execute the Logout() method. What am I missing? Should I be approaching this differently?


Viewing all articles
Browse latest Browse all 9076

Trending Articles