user3272686
user3272686

Reputation: 849

.Net MVC ActionLink inside a Button not working

I have an action link inside a button that doesn't seem to be working:

<div style="position:absolute; top:0px; right:60px;">
    <button class="btn-top btn-vitae shadow-bottom">
        <a href="/Help" target="_blank">Help</a>
    </button>
</div>

The link is supposed to go to ActionResult Index in the HelpController:

public class HelpController : Controller
{
    //
    // GET: /Help/

    public ActionResult Index()
    {
        return View();
    }
} 

Am I missing something?

Upvotes: 0

Views: 1392

Answers (4)

ramiramilu
ramiramilu

Reputation: 17182

One more way is to use Html.ActionLink (Instead of Anchor Tag) -

@Html.ActionLink("Help", "Index", "Home", null, new { target = "_blank" })

Upvotes: 1

Matt Bodily
Matt Bodily

Reputation: 6423

if memory serves you need to swap them

<a href="@Url.Action("Index", "Help")"><input type="button" class="btn-top btn-vitae shadow-bottom" /></a>

Upvotes: 3

Miller
Miller

Reputation: 1156

your action link should include the controller name and action name like this

<a href="/Help/Index" target="_blank">Help</a>

or server side as suggested by @ssimeonov

Upvotes: 1

ssimeonov
ssimeonov

Reputation: 1426

Replace href="/Help" with @(Url.Action("Index", "Help"))

Using Url.Action you will be sure that the correct url is generated no matter what routing you're using.

Upvotes: 2

Related Questions