【问题标题】:How to get absolute url in ASP.NET MVC?如何在 ASP.NET MVC 中获取绝对 URL?
【发布时间】:2011-07-18 06:30:09
【问题描述】:

在我看来,我给出的 URL 是这样的:

<td style="border-bottom: solid 1px #f3ad44" align="center">
    <a class="actions" href="<%= item.URL  %>">www...</a>
</td>

我的问题是 item.URL 的值类似于:www.hello.com 但是当我从网页单击它时,它会导航到 http://localhost:64075/www.hello.com。

如何避免使用 localhost,而实际上导航到 http://www.hello.com?

【问题讨论】:

    标签: c# asp.net-mvc url href


    【解决方案1】:

    确保使用正确的协议(例如 http://)在 URL 前加上 item.URL 或标记中的前缀:[...] href="http://&lt;%= item.URL %&gt;"&gt;[...]。

    【讨论】:

      【解决方案2】:
      <td style="border-bottom: solid 1px #f3ad44" align="center">
           <a class="actions" href="#" onclick="window.open('http://<%= item.URL  %>'); return false;">www...</a> 
      </td> 
      
      <td style="border-bottom: solid 1px #f3ad44" align="center">
           <a class="actions" href="#" onclick="window.location='http://<%= item.URL  %>'; ">www...</a> 
      </td> 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-08
        • 1970-01-01
        • 2010-09-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多