6

In my Controllers i have class AccountController and within in i have this method

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    WebSecurity.Logout();
    return RedirectToAction("Index", "Home");
}

In my Views i have cshtml page with body and this part of code

<form class="float_left" action="Controllers/AccountController" method="post">
    <button class="btn btn-inverse" title="Log out" type="submit">Log   Off</button>
</form>

And this doesn't work, anyone know what is problem or some other simple solution?

3 Answers 3

5

You're not referencing the action method here:

action="Controllers/AccountController"

For starters, you don't need to specify Controllers/ because the framework will find the controller for you. Indeed, the notion of a "folder" of controllers isn't known to the client/URL/etc. What you need to give it is a "route" to the specific action method.

Since the MVC framework knows where the controllers are, you need only tell it which controller and which action method on that controller:

action="Account/LogOff"
Sign up to request clarification or add additional context in comments.

Comments

5

The action attribute is pointing to a wrong controller action. Your controller action is called LogOff and not AccountController. You should never be manually building <form> elements like that but always use the html helpers that are designed for this purpose:

@using (Html.BeginForm("LogOff", "Account"))
{
    <button class="btn btn-inverse" title="Log out" type="submit">Log Off</button>
}

Comments

0

The form action should probably be /Account/LogOff

< form class="float_left" action="/Account/Logoff" method="post">
    <button class="btn btn-inverse" title="Log out" type="submit">Log Off</button>
</form>

Try putting this in the .cshtml file:

@using (Html.BeginForm("LogOff", "Account"))
{
    <button class="btn btn-inverse" title="Log out" type="submit">Log Off</button>
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.