I have an MVC View rendering in Sitecore 7.5 defined as:
Item Name: ViewRenderingA
Item Template: View Rendering
Path: /path/to/ViewRenderingA.cshtml
Data Source: {3AD25922-FE0E-45B3-9F2F-7EF61F678E45} // Item Id of the image in the media library
As you can see, this view rendering has its data source field set to the image item's GUID in the media library. Basically, I am trying to render an image from the media library in a particular static spot of the content item layout.
I statically pull this view rendering in the layout file as:
@Html.Sitecore().Rendering("/path/to/ViewRenderingA")
And then in the Razor View implementation ViewRenderingA.cshtml file, I do this:
@using Sitecore.Mvc
@using Sitecore.Mvc.Presentation
@model RenderingModel
<p>Page Item Name: @Model.PageItem.Name</p> @* <- This correctly shows the content item name. *@
<p>Rendering Name: @Model.Rendering.Item.Name</p> @* <- Why does this also show the content item name instead of the item name of the image in the media library that's linked to the View rendering via data source? *@
I would expect that the Model.Rendering.Item
will be initialized with the media library item that the View Rendering's "Data source" field is pointing to, but it is initialized with the Model.PageItem
instead. It looks like it completely ignores the datasource field. What am I doing wrong?
RenderingContext.Current.Rendering.Item
? Does it work when you add the datasource statically as a parameter to the binding like described in my blog post ctor.io/…? – Kevin BrechbühlRenderingContext.Current.Rendering.Item
also points to the content item (I think it's called "context item") as the other 2. It only works if I add the data source as a parameter like this:@Html.Sitecore().Rendering("/path/to/ViewRenderingA", new { DataSource = "/path/to/datasource-item" })
. Looks like setting the "Data source" filed of the View rendering itself makes no difference. – demisx