Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use anchor tag for calling an Action

First I tried with

<input type="button" value="Something" onclick="location.href='@Url.Action("ActionName")'" />

But this is a button and I want just a link. I've seen somewhere (while wildly browsing the programming forums) a way to hide a button link behind an anchor, but couldn't find/make it.

Then I tried with

<a href="@Html.ActionLink("Something", "ActionName", "ControllerName")"></a>

(here, actually, on the page, the link looked like Something">, whereas the " and > shouldn't be there)

and also

<a href="@Url.Action("ActionName", "ControllerName")">Something</a>

but the latter 2 ways (with the anchor tag) don't work, by means, I don't get directed to the other page. So, any suggestions about how to hide a button behind a link, or how to make the anchor tags run ?

like image 272
Syspect Avatar asked Sep 10 '13 08:09

Syspect


1 Answers

You want an anchor, but the suggested code doesn't work. Try this way (it worked for me):

<a onclick="location.href='@Url.Action("ActionName")'">Something</a><br />

It will work this way, but you will not have the hand, when you hover the link. So just add href="#", like that:

<a href="#" onclick="location.href='@Url.Action("ActionName")'">Something</a><br />
like image 53
Milkncookiez Avatar answered Sep 21 '22 22:09

Milkncookiez