Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Per Erik Gransøe 8 posts 29 karma points
    May 08, 2013 @ 00:40
    Per Erik Gransøe
    0

    Getting CurrentPage from SurfaceController

    Hi

    I have a SurfaceController with a couple of methods to handle a corresponding model I have. As I need to set the Layout inheritance of the views of my SurfaceController, I have my model subclassing the umbraco RenderModel, as described here: http://our.umbraco.org/forum/templating/templates-and-document-types/40252-Umb-6-Custom-Model-The-model-item-passed-into-the-dictionary-is-of-type-requires-UmbracoWebModelsRenderModel.

    My model looks like in the article link:

    public class CustomModel : RenderModel {
     
    public CustomModel() : this(new UmbracoHelper(UmbracoContext.Current).TypedContent(UmbracoContext.Current.PageId)) { }
     
    public CustomModel(IPublishedContent content, CultureInfo culture) : base(content, culture) { }
     
    public CustomModel(IPublishedContent content) : base(content) { }
    }

    In one of my SurfaceController methods, I new up my CustomModel by its default ctor, which results in an invocation of the UmbracoHelper to find the current PageId. And here is the issue - this value is null, and the model creation fails.

    I've tried also to pass on the CurrentPage of the SurfaceController instance to the ctor of my model, but this also fails. The SurfaceController method is a GET operation triggered from an @Html.ActionLink in a view of my controller. Btw. when I hit my first operation of my controller (triggered by an @Html.Action in my umbraco template, the CurrentPage value is fine and set, but not on the subsequent methods.

    I use umbraco version 6.0.5.

    PS: The problem wouldn't exist if I could use a model which did not have to inherit from RenderModel, but I guess this is needed when specifying the Layout of the views (or am I wrong?)

     

Please Sign in or register to post replies

Write your reply to:

Draft