在 Orchard 中使用 FindView [英] Using FindView in Orchard

查看:50
本文介绍了在 Orchard 中使用 FindView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用:

var viewEngineResult = ViewEngines.Engines.FindView(ControllerContext, myViewName, null);

作为渲染视图内容以发送格式良好的电子邮件的过程的一部分.我在果园控制器中使用它.我在 MVC 项目中使用了 Orchard 之外的类似代码,并且运行良好.

as part of a process to render the contents of a view to send nice formatted emails. I'm using it inside an Orchard Controller. I have used similar code outside of Orchard in an MVC project and it works fine.

但是在 Orchard 中运行此代码无法找到我正在寻找的视图并返回搜索了 0 个位置的视图引擎结果.

However in Orchard running this code fails to find the view I'm looking for and returns a view engine result that has searched 0 locations.

viewEngineResult 被调用后具有以下值:

viewEngineResult has the following values after it is called:

  • SearchedLocations: Count = 0,
  • 视图:空,
  • 视图引擎:空

这是否有原因在 Orchard 中不起作用?有没有办法让它起作用?

Is there a reason this doesn't work in Orchard and is there a way to make it work?

推荐答案

我想你应该仔细看看 Orchard.Framework/Mvc/ViewEngines,特别是 IViewEngineProvider 和 ThemeAwareViewEngine.在 Orchard 中还有很多事情要做,例如主题、多租户和更丰富的环境,这些通常可能需要使这项工作发挥作用.这里可能发生的情况是视图引擎没有足够的信息来解析视图,因此选择退出链.您可能希望在 ThemeAwareViewEngine.FindView 中放置一个断点,然后检查该类的私有依赖项字段.如果它们为空,我不会感到惊讶,因为通过静态获取 FindView 可能不允许依赖注入正确地完成它的工作.再说一次,我只是猜测.

I think you'll want to take a close look at Orchard.Framework/Mvc/ViewEngines, in particular IViewEngineProvider and ThemeAwareViewEngine. There's a lot more going on when in Orchard, such as themes, multi-tenancy, and a richer environment in general that may be needed to make this work. What's likely happening here is that the view engines don't have enough information to resolve a view and thus opt out of the chain. You might want to put a breakpoint into ThemeAwareViewEngine.FindView, and then inspect the private dependency fields of that class. I wouldn't be surprised if they were null, because getting to FindView through statics will probably not allow dependency injection to do its stuff properly. Then again I'm just guessing.

这篇关于在 Orchard 中使用 FindView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆