自定义区域中的ASP.NET Core 3.1 MVC视图的设计与默认区域中的视图没有相同

时间:2020-03-30 01:38:56

标签: c# asp.net-mvc asp.net-core

我是ASP新手,正在创建ASP.NET Core 3.1 MVC应用程序。我刚刚了解了一些领域,并创建了一个名为卖方。

我添加了一个控制器:

let a: { x: string } = { x: "" }; // subtype
let b: { x: string | number }; // supertype 
b = a; // aliasing
b.x = 1; // mutation
a.x.toUpperCase(); // ?? explosion

和一个视图:

[Area("Seller")]
public class SellerController : Controller
{
    public IActionResult Index()
    {
        return View();
    }
}

现在我的问题是视图看起来像这样:

我还有另一个问题是这条线:

<h1>Hello @User.Identity.Name</h1>
<p>Use the menu below or the navigation bar to navigate the site</p>
<ul>
    <li class="nav-item">
        <a class="nav-link text-dark" asp-area="Seller" asp-controller="SellerProduct" asp-action="Index">ProductManagement</a>
    </li>
</ul>

行为不像链接,但是像文本,我的意思是“ ProductManagement”是写在卵石上的,但是如果我单击它或将鼠标悬停在它上面,则什么都不会发生

如何使用默认页面所具有的默认设计,就像这样。

enter image description here

如果相关的话,我也使用以下代码调用SellerControler:

<a class="nav-link text-dark" asp-area="Seller" asp-controller="SellerProduct" asp-action="Index">ProductManagement</a>

谢谢您的帮助。

2 个答案:

答案 0 :(得分:2)

样式:
您宁愿将Layout添加到模板中,或将_ViewStart.chtml添加到Area文件夹中:

在模板中:
Layout = "~/Views/Shared/_Layout.cshtml";

_ViewStart.chtml(区域>卖方>视图):

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

答案 1 :(得分:1)

要共享整个应用程序的通用布局,请将_ViewStart.cshtml从您的Views/Shared/_Layout.cshtml移动到应用程序根文件夹。

请参阅https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-3.1#shared-layout-for-areas-using-the-_viewstartcshtml-file

我遇到的另一个问题是这一行: <a class="nav-link text-dark" asp-area="Seller" asp-controller="SellerProduct" asp-action="Index">ProductManagement</a> 行为不像链接,但是像文本,我的意思是“ ProductManagement”是写在卵石上的,但是如果单击它或将鼠标悬停在其上,则不会发生任何事情

标记助手可能无法正常工作,请检查您的/Views/_ViewImports.cshtml以添加

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
相关问题