Copied to clipboard

Flag this post as spam?

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


  • Lewis Smith 208 posts 617 karma points c-trib
    Dec 13, 2017 @ 10:42
    Lewis Smith
    0

    IPublishedContent in Controller

    Hi,

    I'm trying to use IPublishedContent in my controller so instead of Model.Content I want to just call Model

    In the view, you just use

    inherit UmbracoViewPage<IPublishedContent> instead of UmbracoTemplatePage

    Currently my controller is this in the most simple form

    using System.Web.Mvc;
    using Umbraco.Web.Models;
    
    namespace test.Controller
    {
        public class TestDocument : Umbraco.Web.Mvc.RenderMvcController
        {
            public override ActionResult Index(RenderModel model)
            {
                return base.Index(model);
            }
        }
    }
    

    Also, how do i get property values here, I have tried the default Model.Content.GetPropertyValue<string>("valueHere"); or model.Content.GetPropertyValue<string>("valueHere"); wat but its not having that?

    Thanks, Lewis

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 13, 2017 @ 10:48
    Jeroen Breuer
    0

    You can get the current page like this:

    UmbracoContext.Current.PublishedContentRequest.PublishedContent
    

    Jeroen

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 13, 2017 @ 10:49
    Dirk De Grave
    100

    model.Content is IPublishedContent, so you should be able to use .GetPropertyValue

    using Umbraco.Web;
    

    Other option: use CurrentPage, which is also IPublishedContent

    Cheers,

    --Dirk

  • Lewis Smith 208 posts 617 karma points c-trib
    Dec 13, 2017 @ 10:59
    Lewis Smith
    0

    Hi Great! It worked!

    How would I then get this property in my view?

    Lewis

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 13, 2017 @ 11:51
    Dirk De Grave
    0

    Exactly the same way, you said your view is now a

    inherits UmbracoViewPage<IPublishedContent>
    

    so Model will be of IPublishedContent. Again, adding the import statement should be enough to get this working in the view

    --Dirk

Please Sign in or register to post replies

Write your reply to:

Draft