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 @ 13:10
    Per Erik Gransøe
    1

    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: our.umbraco.org/.../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?)

  • Charles Afford 1163 posts 1709 karma points
    May 10, 2013 @ 14:47
    Charles Afford
    0

    Hi, i have not been able to do this esp a problem in partial views and AJAX postaback.  I ended up creating a property in my model to hold the NodeId then setting this in the view then when i post i submit the nodeid in a hidden field, so i have it on post back :).  Hope that helps.

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

    Thanks for your reply.

    My surfacecontroller is triggered by an ActionLink which makes a GET-request:

    @Html.ActionLink("[Some label text]", "[My Controller Operation]", "[My Surface Controller]", new { [My Parameters List })

    So I don't get the my model transferred. For that to happen, I guess I will need an umbraco form and a POST-request?..

  • Charles Afford 1163 posts 1709 karma points
    May 13, 2013 @ 10:04
    Charles Afford
    0

    You could just pass it in the IDictornary (Its a parameter  on the ActionLink) then you could get the id in your controller?

  • Per Erik Gransøe 8 posts 29 karma points
    May 20, 2013 @ 16:38
    Per Erik Gransøe
    0

    Good idea to supply the model as a parameter to the call.

    I actually ended up doing a post request instead (by using an UmbracoForm). This way, the Umbraco context isn't lost. I had a problem if from my sufrace controller's HttpGet-method would return a view which needed the Umbraco context (ie. to do a RenderMacro, or to get and Umbraco Field element).

    Still, I would like to be able to use the ActionLinks and still have my Umbraco context, but I guess I'm in the same boat as the Ajax users waiting for Umbraco to have a general solution for the loss of the Umbraco context.

     

  • Charles Afford 1163 posts 1709 karma points
    May 20, 2013 @ 22:24
    Charles Afford
    0

    There is something coming up for it.  I  dont like the umbraco helper implimetation.  I prefer using the http and ajax request and just passing the value in my model.  Then i have control of what is going on.  Its just me i guess, i like to know what is going on with out relying on something else or someone elses implimentation.  I I dont see any bad having it as a property in a model and have actually found loads of uses it for it esp when trying to  impliment some sort of custom email functions :)  

  • Per Erik Gransøe 8 posts 29 karma points
    May 21, 2013 @ 07:47
    Per Erik Gransøe
    0

    I agree. But the loss of context (ie. with the ActionLink) will stop the flow of having the surface controller to return a view which includes helpers which rely on the umbraco context. 

  • Charles Afford 1163 posts 1709 karma points
    May 21, 2013 @ 10:10
    Charles Afford
    0

    What context are you trying yo use in your actionlink?

Please Sign in or register to post replies

Write your reply to:

Draft