有什么办法可以重用编辑器和编辑器吗?在 asp mvc 应用程序中显示模板?
我们正在开发 3 个 asp mvc 应用程序,所有这些应用程序都需要一些相同的共享编辑器和应用程序。显示模板视图。是否可以以某种方式将它们放入共享组件中并在所有应用程序中以某种方式引用它们,而不是在所有 3 个项目中复制/粘贴这些内容?
We're developing 3 asp mvc applications, all will require some of the same shared editor & display template views. Rather than copy/paste these across all 3 projects, is it possible somehow to put them in a shared component and reference them somehow in all applications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想从 Views 文件夹以外的位置获取视图,则需要创建自己的
ViewEngine
。然后在
Global.asax
中注册您的ViewEngine
:另外,这篇文章可能会有所帮助。 (可惜底部的下载链接已损坏)
编辑:看来此解决方案在实践中不起作用,因为 ASP.NET 不允许从应用程序目录外部加载内容(请参阅 Eilon 的评论)。
但上面的链接,将视图存储在数据库中,仍然可能有帮助。
You're going to need to create your own
ViewEngine
if you want to take to views from a place other than the Views folders.Then to register your
ViewEngine
in theGlobal.asax
:Also, this post might be helpful. (too bad the download link at the bottom is broken though)
Edit : It appears this solution won't work in practice, since ASP.NET won't allow loading content from outside of the application's directory (see Eilon's comments).
But the link above, storing views in DB, could still be helpful.
我不知道如何做到这一点,但必须有一种方法来编译 DLL 中的页面并共享库。
但是,如果您有能力使用自定义视图引擎和另一个模板系统(例如 Stringtemplate),那么您可以像共享库一样共享视图:
I am not sure how it can be done but there must be a way to compile the pages in a DLL and share the library.
But if you can afford to use custom view engine and another template system (for example Stringtemplate) then you can share the views as if you are sharing a library:
要在多个 ASP.NET 应用程序之间共享用户控件(或几乎任何内容),您可以使用此处列出的技巧:http://aspadvice.com/blogs/ssmith/archive/2006/10/05/Tip_3A00_-Share- User-Controls-Between-Applications-in-ASP.NET.aspx
基本思想是将 ASCX 文件放在一个文件夹中,并将该文件夹放入其他应用程序的虚拟文件夹中(您可以有多个虚拟文件夹指向同一个物理文件夹)。
To share user controls (or almost any content) between multiple ASP.NET applications you can use the trick listed here: http://aspadvice.com/blogs/ssmith/archive/2006/10/05/Tip_3A00_-Share-User-Controls-Between-Applications-in-ASP.NET.aspx
The basic idea is to place the ASCX files in a folder and make that folder in to a virtual folder of other applications (you can have multiple virtual folders pointing at the same physical folder).