C# 如何在ASP.NET MVC中获取绝对url?
在我看来,我给出的URL如下:C# 如何在ASP.NET MVC中获取绝对url?,c#,asp.net-mvc,url,href,C#,Asp.net Mvc,Url,Href,在我看来,我给出的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
<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
?确保在项内或标记中使用正确的协议(例如http://
)作为url的前缀。url
或标记:[…]href=“http://“>[…]确保使用正确的协议作为url的前缀(例如http://
),可以在item.URL中,也可以在标记中:[…]href=“http://”>[…]
<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>