SSW Foursquare

Do you avoid hardcoding URLs (“../”, “~/”, or “/”) and use Url.Action or Html.ActionLink instead?

Last updated by Brook Jeynes [SSW] 10 months ago.See history

Hard-coding URLs in your View can cause problems if your routes or page names need to change. Instead, you should always use the Url and Html helpers to refer to different pages in your MVC application.

<a href="/Rule/Create">Create a Rule</a>

Figure: Bad example – Hard-coded URLs may lead to broken links if routes change

@Html.ActionLink("Create a Rule", "Create", "Rule")

Figure: Good example – Use the Url or Html helpers to provide links

We open source. Powered by GitHub