简体   繁体   English

为什么我无法在 ASP.NET Core 应用程序中添加新视图?

[英]Why I can't get the new view added in the ASP.NET Core 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我是 ASP.NET Core 应用程序的新手,我正在尝试添加一个视图,因此我在HomeController.cs中添加了一个函数MYName()并通过单击MYName()函数并选择“详细信息”作为模板

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??如何在标题中创建一个名为MYName并排Privacy选项卡的新选项卡?

// ....  other code

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

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

MYName.cshtml我的名字.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当我使用访问此链接(生根) https://.../Home/MYName

I get the content of the page, but what I need exactly is adding a tab called MYName in the header.我得到了页面的内容,但我真正需要的是在标题中添加一个名为MYName的选项卡。

The header can be updated via the shared _Layout.cshtml file.可以通过共享的 _Layout.cshtml 文件更新标头。 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参考: https ://docs.microsoft.com/en-us/aspnet/core/mvc/views/layout?view=aspnetcore-6.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法在 ASP.NET Core MVC 中添加视图 - I can't add view in ASP.NET Core MVC ASP.NET Core 3.1:为什么我无法获得访问令牌? - ASP.NET Core 3.1: Why can't I get Access Token? 我没有找到 ASP.NET 核心 Web 应用程序(新项目与代码) - I didn't found ASP.NET Core Web Application (New project vs code) 使用 Asp.Net Core,如何将视图作为新的浏览器选项卡打开,然后稍后再关闭 - Using Asp.Net Core, how can I open a view as a new browser tab, and then close it again later 我无法在 asp.net 中获取列表框的值,在 Javascript - I can't get values of Listbox in asp.net after it was daynamically added in Javascript 当托管在Azure应用程序服务中时,如何控制添加到ASP.NET核心Web应用程序中的HTTP响应标头? - How can I control the HTTP response headers added to my ASP.NET core web application when hosted in Azure app service? Asp.net 内核如何在视图中获取当前页面? - Asp.net core how can i get current page in View? 为什么我不能使用HttpContext或HttpCookie? (Asp.Net Core 1.0) - Why I can't use HttpContext or HttpCookie? (Asp.Net Core 1.0) 为什么我不能用新播种的超级用户(Asp.Net Core Identity)登录? - Why can't I log in with the newly seeded power user (Asp.Net Core Identity)? ASP.NET Core无法从主体获取对象 - ASP.NET Core can't get object from body
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM