I would like users to be able to see the corresponding URL for an anchor tag generated by Html.ActionLink() when they hover over the link. This is done by setting the title attribute but where I'm stuck is figuring out how to get that value:
@Html.ActionLink(@testrun.Name, "Download", "Trx",
new { path = @testrun.TrxPath }, new { title = ??)
How can I specify the URL that ActionLink is going to generate? I could hardcode something I guess but that violates DRY.
You could use Url.Action() to generate the Link or you could Create a Custom Helper Method like this:
public static class HtmlHelpers {
public static MvcHtmlString ActionLinkWithTitle(this HtmlHelper helper,
string linkText,
string actionName,
object routeValues) {
return helper.ActionLink(linkText, actionName, routeValues,
new {title = Url.Action(linkText, actionName, routevalues )
}
}
Now basically you will simply need to call your new ActionLinkHelper like this
<%= Html.ActionLinkWithTitle(@testrun.Name, "Download", "Trx",
new { path = @testrun.TrxPath }) %>
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