MVC Surface Controller & Umbraco Current Node

asp.net-mvc, umbraco

Solution

I am using Umbraco 6.0.4 and it is as simple as:

var currentNode = Umbraco.TypedContent(UmbracoContext.PageId);

Problem

I'm trying to write a childaction function in a surface controller that gets called by a macro to render a PartialView. I need in this function to gain access to my current page properties to then tweak the rendered PartialView with. I got this from Jorge Lusar's code on ubootstrap and it works fine on the HttpPost ActionResult function : ``` var renderModel = (UmbracoRenderModel)ControllerContext.RouteData.DataTokens["umbraco"]; var currentPage = renderModel.CurrentNode.AsDynamic(); ``` Problem is I've this error thrown on [ChildActionOnly] PartialViewResult function : ``` Unable to cast object of type 'System.String' to type 'Umbraco.Cms.Web.Model.UmbracoRenderModel'. on 'var renderModel = (UmbracoRenderModel)ControllerContext.RouteData.DataTokens["umbraco"];' ``` Data in DataTokens["umbraco"] seems to change between the two functions. If I diplay DataTokens["umbraco"].ToString() on each one, here is what happens: On [ChildActionOnly] public PartialViewResult Init() -> "Surface" is displayed. On [HttpPort] public HandleSubmit(myModel model) -> "Umbraco.Cms.Web.Model.UmbracoRenderModel" is displayed. Thanks for any advice here. Nicolas.

Original source