U4-1537 - Using CurrentPage in SurfaceController with Html.Action

Created by Jeroen Breuer 24 Jan 2013, 11:33:12 Updated by Sebastiaan Janssen 04 Apr 2013, 14:16:09

Relates to: U4-1536

Relates to: U4-1599

I'm calling a SurfaceController from a view with Html.Action, but when I try to use the CurrentPage property I get the following exception:

Can only use UmbracoPageResult in the context of an Http POST when using the BeginUmbracoForm helper.

However the following does work to get the current page: UmbracoHelper.TypedContent(System.Web.HttpContext.Current.Items["pageID"]);

Comments

Jeroen Breuer 28 Jan 2013, 08:20:05

Another workaround is to get the page from the UmbracoHelper (U4-1527), but it would be nice if this property would also work.


Anthony 28 Jan 2013, 09:55:43

I had this issue. You can also pass CurrentPage into the action.


Jeroen Breuer 29 Jan 2013, 10:00:35

Had a quick look at the SurfaceController in the source. Currently this code is used to return the CurrentPage: ///

/// Gets the current page. /// protected IPublishedContent CurrentPage { get { if (!ControllerContext.RouteData.DataTokens.ContainsKey("umbraco-route-def")) throw new InvalidOperationException("Can only use " + typeof(UmbracoPageResult).Name + " in the context of an Http POST when using the BeginUmbracoForm helper");

    var routeDef = (RouteDefinition)ControllerContext.RouteData.DataTokens["umbraco-route-def"];
    return routeDef.PublishedContentRequest.PublishedContent;
}

} I replaced it with the following code in a custom build: ///

/// Gets the current page. /// protected IPublishedContent CurrentPage { get { return UmbracoContext.Current.PublishedContentRequest.PublishedContent; } } Now CurrentPage always works. With Html.Action or Html.BeginUmbracoForm to a SurfaceController.


Sebastiaan Janssen 04 Apr 2013, 14:16:09

Removing due in 6.1 as this was already implemented in an earlier version, which means it's included in all later versions as well.


Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 4.10.0, 4.11.0, 6.0.0, 4.11.1, 4.11.2, 4.11.3

Due in version: 6.0.1, 4.11.5

Sprint:

Story Points:

Cycle: