我创建了一个View using模块,现在在这个视图的控制器中我需要获取一些特定的内容类型并返回视图。请一些人可以使用代码示例。
答案 0 :(得分:0)
您需要在控制器构造函数中注入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);
}
就是这样。