As the question says, Is it possible to use an ActionLink containing an element, and if not, what is the best way to achieve it?
For example, lets say I have a Span
element, I want the whole thing to be a hyperlink... The following works:
<a href="/Site/Page/@Model.ID?Type=test">
<span class="box5">Click anywhere in this box</span> </a>
Imagine that span/css class box5 makes this large... Was originally a DIV, but, I found that didn't follow standards and this appears to follow ok.
This renders and works fine, but, is there anyway to use an ActionLink instead? I have tried to guess the syntax such as (copying from forms):
@using (Html.Actionlink){<span class="box5">Click anywhere in this box</span>}
and many other combinations without any luck.
Now, my manual HTML workaround works fine and I am happy to leave it, but, is it possible to use a MVC ActionLink, and if it is, should I even worry/would there be any benefits?
Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.
Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
The Anchor Tag Helper generates HTML anchor (<a> </a>) element by adding a new attribute. The "href" attribute of the anchor tag is created by using new attributes. The Anchor Tag Helper generates an HTML anchor (<a> </a>) element by adding new attribute.
Just use @Url.Action instead:
<a href="@Url.Action("Page","Site", new { id = Model.Id, @Type = "test" })">
<span class="box5">Click anywhere in this box</span> </a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With