Copied to clipboard

Flag this post as spam?

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


  • Fredrik 7 posts 38 karma points
    Mar 25, 2015 @ 16:51
    Fredrik
    0

    RenderModel in a SurfaceController

    So I have some trouble figuring out how to get published content from my "Settings" document type in SettingsController : SurfaceController.

    If I do standard hijacking with SettingsModel : RenderModel it gives me my Home document type when using base(UmbracoContext...) Seems logic because I'am calling Html.Action("RenderFooter", "Seetings") from my _Layout view and landing page is Home

    So my question is how do I access "Settings" document type and map my custom model with the properties from there? One side note is that I have two published "Settings" document type because I'm doing one tree for english and one for swedish

    So how do I know which one to get? Is it not possible to get published content with SurfaceController?

    SettingsController

    public class SettingsController : SurfaceController
    {
        public ActionResult RenderFooter(SettingsModel model)
        {
            return PartialView("_Footer", model);
        }
    }
    

    SettingsModel

     public class SettingsModel : RenderModel
    {
    
        public SettingsModel()
            : base(UmbracoContext.Current.PublishedContentRequest.PublishedContent)
        {
            Links = new FooterLinks
            {
                Facebook = Content.GetPropertyValue<string>("facebook"),
                Twitter = Content.GetPropertyValue<string>("twitter"),
                Youtube = Content.GetPropertyValue<string>("youtube"),
                Instagram = Content.GetPropertyValue<string>("instagram")
            };
    
            ContactInfo = new ContactInformation
            {
                Name = Content.GetPropertyValue<string>("companyName"),
                Street = Content.GetPropertyValue<string>("street"),
                Postal = Content.GetPropertyValue<string>("postalCode"),
                Phone = Content.GetPropertyValue<string>("phone"),
                Email = Content.GetPropertyValue<string>("email")
            };
    
            Something = new Something
            {
                Text = Content.GetPropertyValue<string>("something")
            };
        }
    
        public FooterLinks Links { get; set; }
        public ContactInformation ContactInfo { get; set; }
        public Something Something { get; set; }
    
    }
    

    _Layout

    <div>
        Menu etc..
    </div>
    
    <!-- Page content -->
    <div id="body" class="container-fluid">
        @RenderBody()
    </div>
    
    <!-- Footer -->
    <footer class="footer">
        @Html.Action("RenderFooter", "Settings")
    </footer>
    

    _Footer

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Code.Models.SettingsModel>
    <div class="container">
    <div class="row">
        <div class="col-md-4">
            <h3 class="social-media">Social Media</h3>
            <div class="social-media top-buffer">
                <p>@Model.Links.Facebook</p>
                <p>@Model.Links.Twitter</p>
                <p>@Model.Links.Youtube</p>
                <p>@Model.Links.Instagram</p>
            </div>
        </div>
        <div class="col-md-4">
            <div class="footer-two">
                <h3 class="footer-two">Something</h3>
                <div class="top-buffer">
                    <p>@Model.Something.Text</p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="footer-three">
                <h3 class="footer-three">Contact</h3>
                <div class="top-buffer">
                    <p>@Model.ContactInfo.Name</p>
                    <p>@Model.ContactInfo.Street</p>
                    <p>@Model.ContactInfo.Postal</p>
                    <p>@Model.ContactInfo.Phone</p>
                    <p>@Model.ContactInfo.Email</p>
                </div>
            </div>
        </div>
    </div>
    

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Mar 25, 2015 @ 18:15
    Jeroen Breuer
    0

    When you use route hijacking you need to use RenderMvcController or the IRenderMvcController. The Hybrid Framework shows how the IRenderMvcController can be used with a SurfaceController: https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/blob/master/Umbraco.Extensions/Controllers/Base/SurfaceRenderMvcController.cs#L14

    Jeroen

  • Fredrik 7 posts 38 karma points
    Mar 26, 2015 @ 08:26
    Fredrik
    0

    Thank you Jeroen I have a look at it!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies