gpt4 book ai didi

asp.net-mvc-2 - 带有 LinkText = 绝对 URL 的 ASP.NET MVC ActionLink

转载 作者:行者123 更新时间:2023-12-04 17:41:04 24 4
gpt4 key购买 nike

<%: Html.ActionLink("Share Me", "Index", "Mall", new { username = Model.Username }, null)%>

根据映射路线得出预期结果:
<a href="/Mall/Username">Share Me</a>

然而,我需要它不说 Share Me 而是显示绝对 URL,以及使用绝对 URL 作为 href:
<a href="http://www.url.com/Mall/Username">http://www.url.com/Mall/Username</a>

我觉得这不是一项艰巨的任务,但是在处理 MVC 方面非常环保,我很难弄清楚。

最佳答案

与其使用 Html.ActionLink,不如看看 Url.RouteUrl(ActionLink 在内部使用它)。就像是...

<% var myUrl = Url.RouteUrl("Default", new { action = "Mall", username = Model.Username }, Request.Url.Scheme).ToString() %>

<a href="<%:myUrl%>"><%:myUrl%></a>

注意第一个参数是路由名称。

关于asp.net-mvc-2 - 带有 LinkText = 绝对 URL 的 ASP.NET MVC ActionLink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3779156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com