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>
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.
CodePudding user response:
The header can be updated via the shared _Layout.cshtml file. Change this code to reflect:
<ul >
<li >
<a asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li >
<a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
<li >
<a 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