简体   繁体   English

在Razor和Webformview页面中共享一个局部视图

[英]Share one partial view in Razor and Webformview pages

I have number of projects that use different view engines (razor and webform). 我有许多使用不同的视图引擎(剃刀和Webform)的项目。 I want to share a partial view between them. 我想在他们之间分享部分看法。 I want to put my partial view in base project and just link partial views in my projects to it. 我想将我的部分视图放在基础项目中,而只是将我的项目中的部分视图链接到它。

Looks like it isn't possible because partial view in razor and webform inherited from different base classes. 看起来这是不可能的,因为剃刀和Webform中的局部视图是从不同的基类继承的。 Is it possible to hack this? 有可能破解吗?

It was more simple that I though. 不过,我更简单。 WebForm can't take in Razor partial view. WebForm无法使用Razor部分视图。 BUT Razor view engine takes in WebForm partial view. 但是Razor视图引擎采用WebForm部分视图。 So it isn't issue at all. 因此,这根本不是问题。

What I did. 我做了什么。

  1. Create some shared project. 创建一些共享项目。
  2. Add Partial.ascx file (and some js files) in sub folder of this shared project. 在此共享项目的子文件夹中添加Partial.ascx文件(和一些js文件)。
  3. Add reference to this project to my sub projects. 将此项目的引用添加到我的子项目中。
  4. Add as link partial view (and some js files) to sub projects. 将部分视图(和一些js文件)添加为子项目的链接。

So now we have partial view that is shared between number of projects. 因此,现在我们有了在多个项目之间共享的局部视图。

PS: Be aware, my projects have only one view engine for improving performance. PS:请注意,我的项目只有一个视图引擎可以提高性能。 All other were removed: ViewEngines.Engines.Clear(); 其他所有内容均已删除: ViewEngines.Engines.Clear(); and added ViewEngines.Engines.Add(new RazorViewEngine()); 并添加了ViewEngines.Engines.Add(new RazorViewEngine()); Razor only. 仅剃刀。 So I have to remove this code from my Global.asax file. 因此,我必须从Global.asax文件中删除此代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM