Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why I can't get the new view added in the Asp .net application?

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??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

// ....  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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading