Why I can't get the new view added in the ASP.NET Core application?

Issue

I’m newer to ASP.NET Core applications and I’m trying to add a view, so I’ve added a function MYName() in HomeController.cs and I have created a view by clicking on MYName() function and choosing "Details" as a template

Unfortunately, I didn’t get anything in the header of the page.

How can I create a new tab in the header called MYName side by side Privacy tab??

// ....  other code

    public IActionResult Privacy()
    {
        return View();
    }

    public IActionResult MYName()
    {
        return View();
    }

MYName.cshtml

@{
    ViewData["Title"] = "MYName";
}

<h1>@ViewData["Title"]</h1>

<p> My Name is Mohamed </p>

enter image description here

Update :

When I use visit this link ( rooting ) https://.../Home/MYName

I get the content of the page, but what I need exactly is adding a tab called MYName in the header.

Solution

The header can be updated via the shared _Layout.cshtml file.
Change this code to reflect:

                <ul class="navbar-nav flex-grow-1">
                    <li class="nav-item">
                        <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="MYName">My Name</a>
                    </li>
                </ul>

Reference: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/layout?view=aspnetcore-6.0

Answered By – WyattBradley

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.