搜索视图时可以交错使用两个 MVC 视图引擎吗?
我在 MVC 项目中使用 WebForms 和 Razor 视图引擎。他们在一起工作得很好。但是,我设置了一个基于继承的项目,因此我有多个从基础项目派生的子项目。如果只有一个视图引擎,MVC 将在子项目中搜索视图,如果找不到,它将搜索基础视图。
然而,当添加第二个视图引擎时,这种搜索模式被打破,WebForms 引擎搜索子视图,然后搜索基视图,然后 Razor 引擎搜索子视图,然后搜索基视图。因此,基本 .aspx 视图将优先于子 .cshtml 视图。换句话说,当搜索名为 MyView 的视图时,这是搜索位置的优先级列表:
Child\MyView.aspx
Base\MyView.aspx
Child\MyView.cshtml
Base\MyView.cshtml
我想要的是让两个引擎在检查基础项目之前分别检查子项目,如下所示:
Child\MyView.aspx
Child\MyView.cshtml
Base\MyView.aspx
Base\MyView.cshtml
这可能吗?如果是这样,有人可以指出我正确的方向吗?
I'm using the WebForms and Razor view engines in my MVC project. They work just fine together. However, I have an inheritance-based project set up, such that I have multiple child projects derived from a base project. With just one view engine, this works such that MVC will search for a view in the child projects, and failing to find it, it will search the base.
However, when adding the second view engine, this search pattern is broken, such that the WebForms engine searches the child and then the base, and then the Razor engine searches the child and then the base. As such, a base .aspx view will be given priority over a child .cshtml view. In other words, when searching for a view named MyView, this is the prioritized list of locations searched:
Child\MyView.aspx
Base\MyView.aspx
Child\MyView.cshtml
Base\MyView.cshtml
What I want is to have the two engines each check the child projects before either checks the base project, as such:
Child\MyView.aspx
Child\MyView.cshtml
Base\MyView.aspx
Base\MyView.cshtml
Is this possible, and if so, can someone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写自己的视图引擎,在内部使用现有的视图引擎。
You could write your own view engine that uses both existing view engines internally.