Orchardcms 在Orchard CMS中获取内容类型

Orchardcms 在Orchard CMS中获取内容类型,orchardcms,orchardcms-1.7,Orchardcms,Orchardcms 1.7,我已经使用模块创建了一个视图,现在在这个视图的控制器中,我需要获取一些特定的内容类型并返回到视图。请给我一些代码样本 您需要在控制器构造函数中注入IContentManager服务请参见依赖项注入,但由于您需要填充新形状,因此可以在一个实例中注入IOrchardServices,其中包括一些常见的OrchardServices IOrchardServices services; public MyController(IOrchardServices services){ thi

我已经使用模块创建了一个视图,现在在这个视图的控制器中,我需要获取一些特定的内容类型并返回到视图。请给我一些代码样本

您需要在控制器构造函数中注入IContentManager服务请参见依赖项注入,但由于您需要填充新形状,因此可以在一个实例中注入IOrchardServices,其中包括一些常见的OrchardServices

 IOrchardServices services;
 public MyController(IOrchardServices services){
     this.services = services;
 }      
然后,在您的操作中,如果您想在前端显示它,您必须将其标记为主题,请执行以下操作:

[Themed]
public ActionResult MyAction(){
  //Notice that you can filter the contentItems here, this is just a basic example
  var myContentItems = services.ContentManager.Query().ForType("MyContentItem").List();

 //You probably need to create a new shape for showing the ContentTypes
  var shape = services.New.YourCustomShape(); //Notice that you must create a view that matches this name
  shape.YourContentItems = myContentItems;
  return new ShapeResult(this, shape);
}

就这样。

再看看这个