我已经使用模块创建了一个视图,现在在这个视图的控制器中我需要获取一些特定的内容类型并返回到视图。请有人用代码示例详细说明一下。
问问题
569 次
1 回答
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);
}
就是这样。
于 2013-12-29T12:39:04.007 回答