How to properly encode links to external URL in MVC Razor
Two ways :
1. update the database column with full link:
eg SQL
:
update ProductTable set ProductLink='http://www.example.com/Product/Mobiles' where ID=123
In asp mvc view
<a href="@model.ProductLink">View</a>
2. Hardcode the http
part and list from model
<a href="http://@model.ProductLink">View</a>
Hope helps someone.
You don't need to use @Html.ActionLink
for that. Just use a plain A tag:
<a href="http://subdomain.mydomain.com/SomeSite">SomeSite</a>
Html.ActionLink
is specifically for generating links to actions defined in MVC controllers, in the same app. Since you're linking to an absolute URL, you don't need any of the functionality that Html.ActionLink
provides.