我希望用户在悬停链接时能够看到Html.ActionLink()生成的锚标记的相应URL。这是通过设置title属性来完成的,但我卡在了如何获取该值上:
@Html.ActionLink(@testrun.Name, "Download", "Trx",
new { path = @testrun.TrxPath }, new { title = ??)
我该如何指定ActionLink生成的URL?我猜可以硬编码,但这违反了DRY。
我希望用户在悬停链接时能够看到Html.ActionLink()生成的锚标记的相应URL。这是通过设置title属性来完成的,但我卡在了如何获取该值上:
@Html.ActionLink(@testrun.Name, "Download", "Trx",
new { path = @testrun.TrxPath }, new { title = ??)
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 )
}
}
<%= Html.ActionLinkWithTitle(@testrun.Name, "Download", "Trx",
new { path = @testrun.TrxPath }) %>
<script type="text/javascript">
$(function () {
$(selector).each(function () {
$(this).attr("title", $(this).attr("href"));
});
});
</script>
Url.Action() 方法应该可以正常工作。
@Html.ActionLink(@testrun.Name, "Download", "Trx",
new { path = @testrun.TrxPath }, new { title = Url.Action("Download", "Trx") })
但我不确定是否有更好的方法。
new { title = Url.Action("Download", "Trx") }
。 - Michael Shimmins