Copied to clipboard

Flag this post as spam?

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


  • Beau D'Amore 29 posts 70 karma points
    Jun 16, 2014 @ 23:26
    Beau D'Amore
    0

    SurfaceControllers won't inherit templates?

    I have a few SurfaceControllers I am using to get to some custom GPS data.

    Thing is, I want/need these SurfaceControllers to 'play nice'. 

    I tried putting  

    {

    Layout = "_Layout.cshtml";

    }

    at the top of the View for one of the actions and I get this error:

    Cannot return the IPublishedContent because the UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request.

    as it tries to parse Umbraco.Field from the template like so:

    Line 13:     <title>@Umbraco.Field("title", altFieldAlias: "pageName") | @Umbraco.Field("siteName", recursive: true)</title>
    

    I thought SurfaceControllers were like being on a page?...

    help?... drowning... :) 

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Jun 17, 2014 @ 12:57
    Steve Morgan
    0

    How are you trying to use the Surface Controller?  It sounds like you're drowning in how "standard" MVC works with Umbraco.

    Try following through this method - it's for a members area (providing a custom register form using MVC) but I see no reason why you couldn't be getting and rendering data from a third party DB / set of tables.  The Surface Controller would then be useful to handle calls from user controls for pagniation / sorting etc on that data I guess. http://siempresolutions.co.uk/blog/Umbraco_Members_Protected_Area_of_Website_Part_2_Using_MVCMembers_Controller ;  - There's a link to download the sourcecode from Github on that page - you might need to have a quick scan through part 1 of that blog post though as this built upon an attempt at using soley Razor for a Members area (so not so relevant here).

    Once you've got your MVC goodies ready you then "include" your SurfaceController output inside a standard Umbraco template using something like this:

    @Html.Action("MvcMemberRegisterRenderForm", "MvcMemberSurface")

    e.g. as part of the standard content of Umbraco:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }<div id="main-container">
        <div id="main" class="wrapper clearfix">
            <section>
                <h2>@Umbraco.Field("pageTitle")</h2>
                <p>@Umbraco.Field("bodyText")</p>
                @Html.Action("MvcMemberRegisterRenderForm", "MvcMemberSurface")
            </section>    
        </div> <!-- #main -->
    </div> <!-- #main-container -->
     

    This would be my approach - happy to be corrected on this?!  It means you leave the page rendering up to Umbraco and then just insert the bits you need from custom MVC code. 

    Again - would love to hear from others on this approach. 

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jun 17, 2014 @ 13:14
    Sebastiaan Janssen
    0

    Sounds like what you're trying to do is add data to the view before the page loads, correct?
    Your view is not currently inheriting from UmbracoTemplatePage I assume?

    Perhaps this will help: http://24days.in/umbraco/2013/creating-reusable-code-in-mvc-apps/

    Or, maybe a bit easier, read this section on "Handling Partial Views" http://www.proworks.com/blog/2013/02/22/umbraco-6-views,-partial-views,-and-partial-view-macro-files/

    But I can't really make out from your post how far down the rabbit hole you've gone so far.

  • Beau D'Amore 29 posts 70 karma points
    Jun 17, 2014 @ 16:16
    Beau D'Amore
    0

    Thanks for the replies :) 

    Here's some more info... Yes, Steve, I understand how to do it that way. Is that the only way to implement SCs? as HTML.Actions?

    What was trying to do was use my sirface controller as, like, a page in the site. eg:

    From this in my template: @Html.ActionLink("See Your Tracks!", "Tracks", "TrackHistorySurface" ,new { id = memberID }, null)

    Becomes this link: http://localhost:1832/umbraco/Surface/TrackHistorySurface/Tracks/1077 (hits my SC TrackHistorySurface at action Tracks with the memberid 1077)

    upon hitting this actual surface controller at the above link, all that is rendered is the action by itself... no styling, no Layout..

    Having: @Html.Action("Tracks", "TrackHistorySurface", new { id = memberID }) in my template DOES render the action inside the template...

    However, I was hoping to have a friendlier URL such as the ActionLink first described... See my dilemma? I'm missing something MVC-ish... (newer to MVC, coming from long-time web forms) These views would be social sharing endpoints for, say, posting to FB, for example. (Nevermind somehow tweaking the ActionLinks to remove 'umbraco/Surface/')

    Am I approaching this correctly? If I add a controller that is a RenderMvcController, I can't access it via http://localhost:1832/umbraco/Surface/MyController since it isn't a SurfaceController, and can't access it via http://localhost:1832/api/MyController or http://localhost:1832/MyController or anywhere.. missing something here too...

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Jun 17, 2014 @ 16:58
    Steve Morgan
    0

    It's not something I've done - try reading around the Route Hijacking material http://our.umbraco.org/documentation/Reference/Mvc/custom-controllers - this looks like what you're trying to do but by the sounds of it you would have already seen this and I'm misunderstanding. 
     

  • Beau D'Amore 29 posts 70 karma points
    Jun 17, 2014 @ 20:22
    Beau D'Amore
    0

    #Steve, Yes, I read that too.. I guess I'm not MVC saavy enough yet to understand it... (I think I'm asking >1 question in this topic as well.. maybe I should segregate problems...)

    #Sebastiaan, yes, I think not inheriting from UmbracoTemplatePage is causing a problem. If I try something like

    @model IEnumerableTRACK>

    @{

        Layout = "~/Views/umbLayout.cshtml";

     

    }

    inside my strongly typed view, it errors all along umnLayout.cshtml like this:

     

    Cannot return the IPublishedContent because the UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request.

    Somehow I need to blend the world Umbraco and my extra API controllers for managing iOS/GPS data. That would be KEY. I could keep the Google-friendly URLs and still wrap my controllers in the layouts....

    so, any idea as to why I can't have a layout for a strongly typed view that doesn't inherit from UmbracoTemplatePage?

    FYI, in my view, first line is:

     

    @model IEnumerable<MaryRuns.Models.TRACK>

    TWEAK: this is coming from a LINQ to SQL Classes dbml I added and dragged in my two custom tables I added to the U7 DB... manually added, not via some BO interface...

  • Blom 7 posts 27 karma points
    Jun 18, 2014 @ 04:21
    Blom
    0

    Use @inherits Umbraco.Web.Mvc.UmbracoViewPage<YourModel> for extendability with umbraco and using models, should remove error, if i understand correctly.

    Basicly it enables you to use umbraco in view, but it automaticly does @model for you, so you can call your @Model like that as you normally would. (yea that explanation will do, going to bed now ;))

    As you cannot have @inherit and @model in same view file :)

  • Beau D'Amore 29 posts 70 karma points
    Jun 18, 2014 @ 16:57
    Beau D'Amore
    0

    Yes, I have done what you say, like this:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IEnumerable<MaryRuns.Models.TRACK>>

    @{

        Layout = "~/Views/umbLayout.cshtml";

        ViewBag.Title = "Track";        

     

    }

    and I get a diff error like this:

     

    The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MaryRuns.Models.TRACK]', but this dictionary requires a model item of type 'Umbraco.Web.Models.RenderModel'.

    So confused now...

    I just want my sorface controllers wrapped in layouts like other content pages... any ideas?... I can post the full code of each file if needed

  • Blom 7 posts 27 karma points
    Jun 18, 2014 @ 18:45
    Blom
    0

    Oh i just tried with an actual model, yes i get same error.

    Looking through the stack trace my first impression is that its unable to be used like a regular controller, it requires IPublishedContent, which is essentially your Content node in umbraco.

    So im presuming that surface controllers are meant to be rendered in contents and not as a seperate functionality else it would render the CMS useless and might aswell use regular mvc.

    A render model takes a model, so in every view you got a node (content) behind the model used in view, which is what is missing hitting surface controllers directly

  • Blom 7 posts 27 karma points
    Jun 18, 2014 @ 18:51
    Blom
    0

    So create a content that is of template whichever, which has code:

    @Html.Action("Action", "Surface")

  • Beau D'Amore 29 posts 70 karma points
    Jun 18, 2014 @ 19:47
    Beau D'Amore
    0

    Yes, that is exactly what is happening... Can't have my model and the necessary Umbraco Content together ...

    As per your second suggestion about Actions, I specifically do NOT want to do that, as I wrote in earlier posts in this thread.

    This whole exercise is to enable me to have blah.com/trackhistory/tracks/1234 as the actual page, not via an action to a surface controller from a content page like '/tracks'... which gives no URL values to Google/FB/etc as an endpoint URL.

    If i currently go to blah.com/trackhistory/tracks/1234 I get the bare SurfaceController without any style...

  • Blom 7 posts 27 karma points
    Jun 18, 2014 @ 21:31
    Blom
    0

    Been searching and come up short, i cant seem to find a solution.

    But if you just want endpoints, what about API? JSON/XML but with layout i have no idea, im new at umbraco myself aswell.

  • Blom 7 posts 27 karma points
    Jun 18, 2014 @ 21:54
    Blom
    0

    Well you could use the general post/get way maybe.

    Make content that links to a template (its link will be localhost/register, but then make the endpoint with variables such as localhost/register?user=whatever

    then in your content template:

    @Html.Action("Action", "Surface", Request["user"])

    could even make the action a variable. thus you have your endpoint

    Haventh tested, just brain storming.

Please Sign in or register to post replies

Write your reply to:

Draft