Tuesday, December 1, 2015

Creating an external link in ASP.NET MVC

I have been using ASP.NET MVC for a very long time and have frequently used @Html.ActionLink throughout my code base, but I recently needed to create a static link to the Web API Help and I was wondering if there was a standard way of creating a hyperlink using an MVC Razor Html Helper that did not need to go through an MVC Controller.

Well, fortunately, there is!

Instead of using @Html.ActionLink, you simply use @Html.RouteLink as follows:

@Html.RouteLink("Help", new { }, new { href = "/help" })
That was all there is to it!!

No comments:

Post a Comment