【发布时间】:2018-06-11 14:22:26
【问题描述】:
我不能reuse my cshtml files from another assembly。这是简单的示例:
- 使用默认模板(使用Web-Application、Model-View-Controller)创建一个ASP.NET Core Web Application项目,并将其命名为
ViewReuse - 添加一个名为
ViewLibrary的类库 - 在 ViewLibrary 中添加对
Microsoft.AspNetCore.All元包的引用 - 创建一个名为 Views 的文件夹,然后创建另一个名为 Shared 的文件夹,并在其中创建一个名为
ReusedLayout.cshtml的简单 cshtml 文件 - 将
EmbeddedResources Include='Views\**\*.cshtml'添加到 ViewLibrary 的 csproj,以包含 ViewLibrary.dll 中的所有视图 - 在 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:布局视图 找不到“/Views/Shared/ReusedLayout.cshtml”。这 搜索了以下位置:/Views/Shared/ReusedLayout.cshtml
我做错了什么?我该如何解决这个问题?
【问题讨论】:
标签: asp.net-mvc razor reusability