Bernard Polman
Bernard Polman

Reputation: 855

MVC Asp.net - calling ActionResult that redirects to URL on button click

I created a simple ActionResult in AccountController that should redirect to a specific URL:

[Route("account/redirect")]
public ActionResult RedirectGoogle()
{
    return Redirect("https://google.com");
}

And I want to call the action in view using Razor like this:

    <a class="btn btn-primary" href="@Url.Action("RedirectGoogle","AccountController")"> Goto Google</a>

but when clicking the link, nothing happens and the action is not even called. What am I doing wrong?

Upvotes: 0

Views: 513

Answers (1)

Hien Nguyen
Hien Nguyen

Reputation: 18975

You need remove controller text in Url.Action, change to

<a class="btn btn-primary" href="@Url.Action("RedirectGoogle","Account")"> Goto Google</a>

Upvotes: 2

Related Questions