Demian
Demian

Reputation: 65

asp-action and asp-controller executes post method after reedirects

I use from asp-action in order to logout action as:

<form asp-action="Logoff" asp-controller="Account">
    <button type="submit" class="btn-link dropdown-item">
        <i class="mdi mdi-logout font-size-16 align-middle me-1"></i> 
        Logout
    </button>
</form>

So I want to use the same to redirect to a new view, that view has a inside it and the controller has a HttpPost, so when I click on it executes the post method, is there a way to avoid the execution of HttpPost method and still using asp-actions?

I change the button type to button, but it do anything when it's clicked

Upvotes: 0

Views: 345

Answers (1)

Yiyi You
Yiyi You

Reputation: 18179

You can try to add method="get" into the form,so that when you click on it executes the get request:

<form method="get" asp-action="Logoff" asp-controller="Account">
    <button type="submit" class="btn-link dropdown-item">
        <i class="mdi mdi-logout font-size-16 align-middle me-1"></i> 
        Logout
    </button>
</form>

Upvotes: 1

Related Questions