Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit dd9ab08

Browse files
committed
Fakes the route context for the preview controller
Fixes #125
1 parent 83b3742 commit dd9ab08

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Our.Umbraco.DocTypeGridEditor/Web/Helpers/ViewHelper.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,37 @@
33
using System.Web.Mvc;
44
using System.Web.Routing;
55
using Umbraco.Core.Logging;
6+
using Umbraco.Web;
7+
using Umbraco.Web.Mvc;
8+
using UmbracoWebConstants = Umbraco.Core.Constants.Web;
69

710
namespace Our.Umbraco.DocTypeGridEditor.Web.Helpers
811
{
912
internal static class ViewHelper
1013
{
1114
private class DummyController : Controller { }
1215

13-
public static string RenderPartial(string partialName, object model, HttpContextBase httpContext = null)
16+
public static string RenderPartial(string partialName, object model, HttpContextBase httpContext = null, UmbracoContext umbracoContext = null)
1417
{
1518
using (var sw = new StringWriter())
1619
{
1720
if (httpContext == null)
1821
httpContext = new HttpContextWrapper(HttpContext.Current);
1922

23+
if (umbracoContext == null)
24+
umbracoContext = UmbracoContext.Current;
25+
2026
var routeData = new RouteData();
2127
routeData.Values.Add("controller", "DummyController");
2228

29+
if (umbracoContext.PublishedContentRequest != null)
30+
{
31+
routeData.DataTokens[UmbracoWebConstants.UmbracoRouteDefinitionDataToken] = new RouteDefinition
32+
{
33+
PublishedContentRequest = umbracoContext.PublishedContentRequest
34+
};
35+
}
36+
2337
var controllerContext = new ControllerContext(new RequestContext(httpContext, routeData), new DummyController());
2438

2539
var viewResult = ViewEngines.Engines.FindPartialView(controllerContext, partialName);

0 commit comments

Comments
 (0)