[英]How to make asp.net core application to look for view files in the current project?
I have two projects in my solution. 我的解决方案中有两个项目。 One ( main ) of them is the application entry point.
其中一个( 主要 )是应用程序入口点。 The other one ( api ) handles one of the business processes, which require JSON communication in 99% cases.
另一个( api )处理其中一个业务流程,在99%的情况下需要JSON通信。 However, for 1% of cases I need full HTML response, and here is the problem.
但是,在1%的情况下,我需要完整的HTML响应,这就是问题所在。 I created a controller and a view, but it seems that application looks for the view in the main project.
我创建了一个控制器和一个视图,但似乎应用程序在主项目中查找该视图。
I want it to work with the following file structure within the solution: 我希望它与解决方案中的以下文件结构一起使用:
/Main/ (and the content of main application) /API/Controllers/TestController.cs (contains definition of Action()) /API/Views/Test/Action.cshtml
But it seems I need to copy the view from /API/Views/Test/Action.cshtml
to /Main/Views/Test/Action.cshtml
or /Main/Views/Shared/Action.cshtml
. 但是似乎我需要将视图从
/API/Views/Test/Action.cshtml
复制到/Main/Views/Test/Action.cshtml
或/Main/Views/Shared/Action.cshtml
。 That splits internal logic of my application :( 那分裂了我的应用程序的内部逻辑:(
You can keep your views with your DLL. 您可以使用DLL保留视图。 Just ensure on build/deployment copy 'views' folder at root location.
只需确保在根目录下的构建/部署副本“ views”文件夹中即可。
You cannot (currently, at least) share views between ASP.NET Core projects. 您(目前至少)不能在ASP.NET Core项目之间共享视图。 In ASP.NET Core 2.1 (in preview), you will be able to share views by adding them to a class library that both projects can reference.
在ASP.NET Core 2.1 (预览版)中,您可以通过将视图添加到两个项目都可以引用的类库中来共享视图。
Razor UI in a class library
类库中的Razor UI
ASP.NET Core 2.1 will make it easier to build and include Razor based UI in a library and share it across multiple projects.
ASP.NET Core 2.1将使构建和在库中包含基于Razor的UI以及在多个项目之间共享它变得更加容易。 A new Razor SDK will enable building Razor files into a class library project that can then be packaged into a NuGet package.
新的Razor SDK将支持将Razor文件构建到类库项目中,然后可以将其打包到NuGet包中。 Views and pages in libraries will automatically be discovered and can be overridden by the application.
库中的视图和页面将被自动发现,并且可以被应用程序覆盖。 By integrating Razor compilation into the build, the app startup time is also significantly faster, while still allowing for fast updates to your Razor views and pages at runtime as part of an iterative development workflow.
通过将Razor编译集成到内部版本中,应用程序的启动时间也大大缩短,同时仍允许在运行时快速更新Razor视图和页面,这是迭代开发工作流程的一部分。
For the time being, you'll just have to duplicate the views in each project and put it on your road map to factor them out once 2.1 is released and you can upgrade. 暂时,您只需要在每个项目中复制视图并将其放在路线图上就可以在2.1发布并可以升级时将它们排除在外。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.