Skip to content

Instantly share code, notes, and snippets.

@cassidydotdk
Created August 11, 2016 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cassidydotdk/43e8cd2c885c663d46d04f208fa1502a to your computer and use it in GitHub Desktop.
Save cassidydotdk/43e8cd2c885c663d46d04f208fa1502a to your computer and use it in GitHub Desktop.
Quickly render a Sitecore Controller Rendering, using given Item as Datasource
public virtual HtmlString RenderItem(Item item, string controller, string action)
{
Assert.ArgumentNotNull(item, "item");
Assert.ArgumentNotNullOrEmpty(controller, "controller");
Assert.ArgumentNotNullOrEmpty(action, "action");
var r = new Rendering();
r.DataSource = item.Paths.FullPath;
using (RenderingContext.EnterContext(r))
{
var runner = new ControllerRunner(controller, action);
var result = runner.Execute();
return new HtmlString(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment