skip to Main Content

On my site I have a page on /Home/Index

This is the index page in my HomeController.

To reach this page I have the link:

<li class="nav-item">
     <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>

I want to add the same link for a different page, but this page is located on /Products/Food/Index.
I tried the following:

<li class="nav-item">
     <a class="nav-link text-dark" asp-area="" asp-controller="Products/Food" asp-action="Index">Food</a>
</li>

But this results in /Products%2FFood/Index in the URL bar.

What can I do to reach this page using the way of referencing pages?

2

Answers


  1. Just use

    <a class="nav-link text-dark" href="/Products/Food/Index">Food</a>
    

    It is basically same with using anchor tag with asp-*, those are tag helpers

    Login or Signup to reply.
  2. May be you need to change the folder structure like create Area "Products" in that Products add Controller "FoodController.cs" then add a view "Index".

    <li class="nav-item">
         <a class="nav-link text-dark" asp-area="Products" asp-controller="Food" asp-action="Index">Food</a>
    </li>
    

    enter image description here

    Sample screenshot

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search