Copied to clipboard

Flag this post as spam?

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


  • Andy Felton 185 posts 484 karma points c-trib
    Oct 11, 2016 @ 15:48
    Andy Felton
    0

    Form Surface Controllers and Partial Views

    Hi,

    I'm working on a bit of code that is using a Form Surface Controller. I've created my model for the form (which contains the 3 fields on the form), a controller and partial view.

    All is working well but I need to be able to get to the root page of the site in the partial view to obtain some fields for the drop downs. As I'm not inheriting from UmbracoTemplatePage what's the easiest way to get to the root page of the site?

    My code for the model is:

    public class FindACarFormModel 
    {
        public string model { get; set; }
        public string price { get; set; }
        public string age { get; set; }
        public string email { get; set; }
    }
    

    In my view I need to be able to do functions like CurrentPage.Site() and Umbraco.Content(). Any help would be appreciated!

    Thanks Andy

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Oct 11, 2016 @ 17:04
    Steve Morgan
    0

    Hi Andy,

    Umbraco.TypedContentAtRoot().First()
    

    or

    Umbraco.ContentAtRoot().First()
    

    Should work.

    HTH

    Steve

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Nov 20, 2016 @ 11:42
    Alex Skrypnyk
    1

    Hi Andy,

    If you want to get root node inside current tree - another possibility is to use:

    var rootNode = Umbraco.AssignedContentItem.AncestorOrSelf("docTypeAliasRootNode");
    

    or

    var rootNode = Umbraco.AssignedContentItem.AncestorOrSelf(1);
    

    And don't use CurrentPage.Site()

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft