0
votes

I have created a View using module, now in controller of this view i need to fetch some specific content type and return to view. Please can some one eleborate with code sample.

1

1 Answers

0
votes

You will need to inject the IContentManager services in your controller constructor (see dependency injection) , but since you will need to populate a new shape, you could inject IOrchardServices which will include a few common OrchardServices in one instance.

 IOrchardServices services;
 public MyController(IOrchardServices services){
     this.services = services;
 }      

Then in your action (if you want to show it on the front end you will have to mark it as themed), do something like this:

[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);

}

And that's it.