簡體   English   中英

自定義區域中的 ASP.NET Core 3.1 MVC 視圖與默認區域中的視圖設計不同

[英]ASP.NET Core 3.1 MVC Views in custom Areas dont have the same design as those in the default one

我是 ASP 的新手,我正在創建 ASP.NET Core 3.1 MVC 應用程序。 我剛剛了解了區域並創建了一個名為賣方的人。

我添加了一個控制器:

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

現在我的問題是視圖如下所示:

我遇到的另一個問題是這一行:

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

行為不像鏈接,但像文本一樣,我的意思是“ProductManagement”正在寫在屏幕上,但是如果我單擊它或將鼠標懸停在它上面,則沒有任何反應

我如何使用默認頁面的默認設計,比如這個。

在此處輸入圖片說明

此外,如果相關,我會使用以下行調用 SellerControler:

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

提前感謝您的幫助。

造型:
您更需要將Layout添加到您的模板或在 Area 文件夾中添加_ViewStart.chtml

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

_ViewStart.chtml (區域 > 賣家 > 視圖):

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

要為整個應用程序共享一個通用布局,請將_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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM