This project is read-only.

showing a content item to the frontend from a custom controller

Topics: Writing modules
Aug 6, 2012 at 4:38 PM

Hey everyone,

I've made a custom controller to create a custom search function.

        public ActionResult Show_Employee(int EmployeeID)
            var viewModel = _contentManager.Get(EmployeeID);
            return View("Show_Employee", viewModel);


I've also created a view Show_Employee

Everything works fine but I feel I'm not using the Orchard functionalities, I'm also losing the url slug functionality here

So my question is, how can i return an employee part item in stead of using my own view?


Aug 6, 2012 at 7:08 PM

Redirect to the item's URL?

Aug 6, 2012 at 7:30 PM


Thanks a lot, that worked, now for the next step, I also want to return a list of employees by criteria for instance where employee.function = teacher

How would I do that?


Aug 8, 2012 at 3:59 PM
Edited Aug 8, 2012 at 3:59 PM

For each content item, build a shape. Add each shape to a new instance of the List shape. From your view, render that List shape.
Here's how you could build a list shape:

var list = Shape.List();
list.AddRange(contentItems.Select(ci => _contentManager.BuildDisplay(ci, "Summary")));

Notice the usage of the "Summary" display type: this will be passed to each driver. Also, the placement binder will use this display type to determine what shapes to create.

To see this in action, checkout the BlogController of Orchard.Blogs.