gpt4 book ai didi

asp.net-mvc - 在 ASP.NET Core MVC 中找不到嵌入式 View

转载 作者:行者123 更新时间:2023-12-03 14:57:40 27 4
gpt4 key购买 nike

我不能reuse my cshtml files from another assembly .这是基本示例:

  • 使用默认模板(使用 Web-Application、Model-View-Controller)创建一个 ASP.NET Core Web 应用程序项目,并将其命名为 ViewReuse
  • 添加一个名为 ViewLibrary 的类库
  • 添加对 Microsoft.AspNetCore.All 的引用ViewLibrary 中的元包
  • 创建一个名为 Views 的文件夹,然后创建另一个名为 Shared 的文件夹,并在其中创建一个名为 ReusedLayout.cshtml 的简单 cshtml 文件。
  • 添加 EmbeddedResources Include='Views\**\*.cshtml'到 ViewLibrary 的 csproj,以包含 ViewLibrary.dll 中的所有 View
  • 在 ViewReuse 项目中,Startup.cs 中,将 MVC 服务的配置更改为 services.AddMvc().ConfigureApplicationPartManager(p => { p.ApplicationParts.Add(new AssemblyPart(typeof(ReusedController).Assembly)); });
  • 更改 About.cshtml使用 ViewLibrary 中的布局:Layout = "/Views/Shared/ReusedLayout.cshtml"
  • 然后运行应用程序,并导航到 /home/about .

  • 对我来说,我遇到了这个错误:

    InvalidOperationException: The layout view '/Views/Shared/ReusedLayout.cshtml' could not be located. The following locations were searched: /Views/Shared/ReusedLayout.cshtml



    我做错了什么?我该如何解决这个问题?

    最佳答案

    尝试右键单击 View 文件并在属性中更改为嵌入资源。

    关于asp.net-mvc - 在 ASP.NET Core MVC 中找不到嵌入式 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48051478/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com