如何列出 Orchard 容器中的项目?
在我的 Orchard 网站中,有一个名为“产品”的内容类型。它具有容器和可路由部分。产品可以包含名为 ProductFeature 的内容类型。
我已经覆盖了 Content-Product.cshtml 视图,以在浏览到 Route url 时修改 html。 在此视图中,如何获取产品包含的所有 ProductFeature 的列表?
这篇文章展示了如何为博客小部件执行此操作。 http://weblogs .asp.net/bleroy/archive/2011/03/27/take-over-list-rendering-in-orchard.aspx
我很难找到如何在产品的内容视图中执行此操作。上面示例中的代码抛出空异常错误,因此模型结构必须不同。我尝试使用形状跟踪或在 Visual Studio 中进行调试来查看模型,但找不到包含的项目。
任何帮助将不胜感激。
In my Orchard site, there is a content type named Product. It has the parts Container and Routable. Products can contain a content type named ProductFeature.
I have overrode the view Content-Product.cshtml to modify the html when browsing to the Route url.
Within this view, how can I get a list of all ProductFeature's the Product contains?
This post shows how to do this for a blog Widget.
http://weblogs.asp.net/bleroy/archive/2011/03/27/taking-over-list-rendering-in-orchard.aspx
I'm having a hard time finding how to do this in the Product's content view. The code from the above example throws a null exception error, so the model structure must be different. I I tried looking at the model using Shape Tracing or debugging in Visual Studio, but couldn't find the contained items.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您确保您的placement.info包含容器部分,那么您的功能列表应该已经显示。
If you make sure your placement.info includes the container part, then your list of features should already being displayed.
我使用两个选项(我知道 Bertrand 会称它们丑陋且不必要,因为他努力为我们提供了许多其他工具,但如果您还没有掌握 Orchard 的全部美丽以及它的巧妙之处,那么您需要这些黑客。)
所以这里有2:
创建部分视图
Parts.Container.Contained-YourContentTypeName.cshtml
内部:
in
Content-YourContentTypeName.cshtml
::在我的例子中至少是
Items[1]
,您可以在模型中检查形状跟踪,其中清单是。从这里开始一切都与 1) 相同。希望它能帮助那些偶然发现这个线程、像我几周前那样寻找这个解决方案的人。
There are two options that I use (I know Bertrand will call them ugly and unnecessary as he has worked hard to give us many other tools, but if you either haven't grasped the full beauty of Orchard and how ingenious it is, you need these hacks.)
So here are 2:
Create a partial view
Parts.Container.Contained-YourContentTypeName.cshtml
inside:
in
Content-YourContentTypeName.cshtml
:At least it is
Items[1]
in my case, you can check with shape tracing in model where the list is. And from here on everything is the same as 1).Hope it helps someone who stumbles upon tis thread, looking for this solution like I did few weeks back.
为了扩展 Zoran 的答案,如果您不想硬编码 Container 在 Items 列表中的位置,您可以使用 LINQ:
...
To expand on Zoran's answer, if you don't want to hard-code the position of Container in the Items list you can use LINQ:
...