ASP MVC href to a controller/view ASP MVC href to a controller/view asp.net asp.net

ASP MVC href to a controller/view


There are a couple of ways that you can accomplish this. You can do the following:

<li>     @Html.ActionLink("Clients", "Index", "User", new { @class = "elements" }, null)</li>

or this:

<li>     <a href="@Url.Action("Index", "Users")" class="elements">          <span>Clients</span>     </a></li>

Lately I do the following:

<a href="@Url.Action("Index", null, new { area = string.Empty, controller = "User" }, Request.Url.Scheme)">     <span>Clients</span></a>

The result would have http://localhost/10000 (or with whatever port you are using) to be appended to the URL structure like:

http://localhost:10000/Users

I hope this helps.


how about

<li><a href="@Url.Action("Index", "Users")" class="elements"><span>Clients</span></a></li>


Try the following:

<a asp-controller="Users" asp-action="Index"></a>

(Valid for ASP.NET 5 and MVC 6)