Skip to main content
edited title
Link
Mark Cassidy
  • 25.4k
  • 7
  • 59
  • 117

Sitecore MVC - Accessing the Data Source of a Control

added code highlights
Source Link
Gatogordo
  • 20.3k
  • 2
  • 39
  • 100

I have a control property with a data source pointing to a folder with items with fields.

Is there a way to loop through the children of the item in the data source and display them on my view?

In my view I have:

@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@model RenderingModel
@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@model RenderingModel

In my controller I have:

    public ActionResult Index()
    {
        var renderingModel = new Sitecore.Mvc.Presentation.RenderingModel();
        var myTitle = renderingModel.PageItem.Fields["Title"].Value;
        var item = Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.Item;
        var itemPageContext = Sitecore.Mvc.Presentation.RenderingContext.Current.PageContext.Item;
        return View();
    }
public ActionResult Index()
{
    var renderingModel = new Sitecore.Mvc.Presentation.RenderingModel();
    var myTitle = renderingModel.PageItem.Fields["Title"].Value;
    var item = Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.Item;
    var itemPageContext = Sitecore.Mvc.Presentation.RenderingContext.Current.PageContext.Item;
    return View();
}

Control Properties

enter image description here

I have a control property with a data source pointing to a folder with items with fields.

Is there a way to loop through the children of the item in the data source and display them on my view?

In my view I have:

@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@model RenderingModel

In my controller I have:

    public ActionResult Index()
    {
        var renderingModel = new Sitecore.Mvc.Presentation.RenderingModel();
        var myTitle = renderingModel.PageItem.Fields["Title"].Value;
        var item = Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.Item;
        var itemPageContext = Sitecore.Mvc.Presentation.RenderingContext.Current.PageContext.Item;
        return View();
    }

Control Properties

enter image description here

I have a control property with a data source pointing to a folder with items with fields.

Is there a way to loop through the children of the item in the data source and display them on my view?

In my view I have:

@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@model RenderingModel

In my controller I have:

public ActionResult Index()
{
    var renderingModel = new Sitecore.Mvc.Presentation.RenderingModel();
    var myTitle = renderingModel.PageItem.Fields["Title"].Value;
    var item = Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.Item;
    var itemPageContext = Sitecore.Mvc.Presentation.RenderingContext.Current.PageContext.Item;
    return View();
}

Control Properties

enter image description here

added 588 characters in body
Source Link
ADH
  • 1.8k
  • 2
  • 15
  • 31

I have a control property with a data source pointing to a folder with items with fields.

Is there a way to loop through the children of the item in the data source and display them on my view?

In my view I have:

@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@model RenderingModel

In my controller I have:

    public ActionResult Index()
    {
        var renderingModel = new Sitecore.Mvc.Presentation.RenderingModel();
        var myTitle = renderingModel.PageItem.Fields["Title"].Value;
        var item = Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.Item;
        var itemPageContext = Sitecore.Mvc.Presentation.RenderingContext.Current.PageContext.Item;
        return View();
    }

Control Properties

enter image description here

I have a control property with a data source pointing to a folder with items with fields.

Is there a way to loop through the children of the item in the data source and display them on my view?

Control Properties

enter image description here

I have a control property with a data source pointing to a folder with items with fields.

Is there a way to loop through the children of the item in the data source and display them on my view?

In my view I have:

@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@model RenderingModel

In my controller I have:

    public ActionResult Index()
    {
        var renderingModel = new Sitecore.Mvc.Presentation.RenderingModel();
        var myTitle = renderingModel.PageItem.Fields["Title"].Value;
        var item = Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.Item;
        var itemPageContext = Sitecore.Mvc.Presentation.RenderingContext.Current.PageContext.Item;
        return View();
    }

Control Properties

enter image description here

deleted 9 characters in body
Source Link
ADH
  • 1.8k
  • 2
  • 15
  • 31
Loading
Removed Sitecore version tag
Link
jammykam
  • 13.9k
  • 2
  • 29
  • 74
Loading
Source Link
ADH
  • 1.8k
  • 2
  • 15
  • 31
Loading