I'm trying to pass some data into a ControllerRendering from a Razor view. I tried to pass it along as an object:
@model SBJSitecore82.Areas.Editorial.Models.ViewModels.IssueSectionViewModel[]
@foreach (var issueSection in Model)
{
@Html.Sitecore().ControllerRendering("Module", "IssueSection", new { area = "Editorial", issueSectionViewModel = issueSection })
}
By in my controller, the object properties are always null, even though they are not null in the Razor view where it called the ControllerRendering.
public ActionResult IssueSection(IssueSectionViewModel issueSectionViewModel)
{
return View(issueSectionViewModel);
}
So I decided to try to pass the object using the Datasource attribute in the Razor view:
@model SBJSitecore82.Areas.Editorial.Models.ViewModels.IssueSectionViewModel[]
@foreach (var issueSection in Model)
{
@Html.Sitecore().ControllerRendering("Module", "IssueSection", new { area = "Editorial", Datasource = issueSection })
}
But that just passes a string into the RenderingContext.Current.Rendering.Datasource
property. I saw an example where someone passed an ID into the Datasource and I presume they just did a GetItem with that ID. I could do the same, but that seems inefficient when I have a dozen of these items to process.
So the question is, how can I pass these objects over, or can I? Or should I just pass the ID over and retrieve the items?
@Html.Partial
and pass the model through?