Skip to main content
Updated to include full ComponentController class
Source Link
Chris Morgan
  • 7.3k
  • 17
  • 32

Assuming this is DD4T 2, rendering partial views for Component Presentations, and that you have all the dependency injection etc setup, your most basic version of this method should be:

public class ComponentController : ModelControllerBase
{
    public ComponentController(IPageFactory pageFactory, IComponentPresentationFactory componentPresentationFactory, 
        ILogger logger, IDD4TConfiguration dd4tConfiguration, 
        IViewModelFactory viewModelFactory) 
        : base(pageFactory, componentPresentationFactory, logger, dd4tConfiguration, viewModelFactory)
    {
    }

    public override ActionResult ComponentModel()
    {
        return base.ComponentModel();
    }
}

With the following in your page layout

@foreach (var item in Model.Items)
{
   @Html.Render(item)
}

Assuming this is DD4T 2, rendering partial views for Component Presentations, and that you have all the dependency injection etc setup, your most basic version of this method should be:

public override ActionResult ComponentModel()
{
   return base.ComponentModel();
}

With the following in your page layout

@foreach (var item in Model.Items)
{
   @Html.Render(item)
}

Assuming this is DD4T 2, rendering partial views for Component Presentations, and that you have all the dependency injection etc setup, your most basic version of this method should be:

public class ComponentController : ModelControllerBase
{
    public ComponentController(IPageFactory pageFactory, IComponentPresentationFactory componentPresentationFactory, 
        ILogger logger, IDD4TConfiguration dd4tConfiguration, 
        IViewModelFactory viewModelFactory) 
        : base(pageFactory, componentPresentationFactory, logger, dd4tConfiguration, viewModelFactory)
    {
    }

    public override ActionResult ComponentModel()
    {
        return base.ComponentModel();
    }
}

With the following in your page layout

@foreach (var item in Model.Items)
{
   @Html.Render(item)
}
Source Link
Chris Morgan
  • 7.3k
  • 17
  • 32

Assuming this is DD4T 2, rendering partial views for Component Presentations, and that you have all the dependency injection etc setup, your most basic version of this method should be:

public override ActionResult ComponentModel()
{
   return base.ComponentModel();
}

With the following in your page layout

@foreach (var item in Model.Items)
{
   @Html.Render(item)
}