12

I'm currently trying to make a website in ASP.NET Core MVC. In my layout page, I'm making a navigation bar to access all of the actions that can be reached through my controllers. I am however unable to create useful links.

<ul>
        <li><a href="homepage">Home</a></li>
        <li><a href="index">Index</a></li>
</ul>

My problem with this is that I still need the controller before the links and if I put the controller in front of the action like this

<ul>

        <li><a href="home/homepage">Home</a></li>
        <li><a href="home/index">What We've Done</a></li>
</ul>

When I click on one link and then the other, the link will end up being "myurl/home/home/page".

How can I create the link to only link to the exact page I want to?

2
  • have you tried using Razor instead of html? Commented Jul 6, 2016 at 18:57
  • Please, don't use MVC6 tags anymore. It's for a future version of ASP.NET MVC based on the old webstack (MVC5). ASP.NET Core is a complete new and incompatible, portable version based on .NET Core. Commented Jul 8, 2016 at 11:35

1 Answer 1

27

You should use the anchor tag helper to build the markup for the link

<a asp-action="index" asp-controller="home">Home</a>

This will generate the correct relative path to the index action as the href property value of the anchor tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.