Created
August 11, 2016 09:03
-
-
Save cassidydotdk/43e8cd2c885c663d46d04f208fa1502a to your computer and use it in GitHub Desktop.
Quickly render a Sitecore Controller Rendering, using given Item as Datasource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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