Copied to clipboard

Flag this post as spam?

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


  • LeadMagnet 7 posts 76 karma points
    Oct 12, 2018 @ 14:16
    LeadMagnet
    0

    Retreive content from database

    I'm having trouble getting any method of retrieving content from the database to work.

    I have a view, it's blank, no model. I want to display the "siteContent" property from the Content tab of a content article on this view.

    I've tried...

    var umbHelper = new Umbraco.Web.UmbracoHelper(UmbracoContext.Current);

    var mData = umbHelper.Content(1119);

    ...and...

    IPublishedContent content = UmbracoHelper.TypedContent(1119);

    ..and several other things but I either get null exception errors, model errors or blanks. I cannot get the article text to display. It's plain text, entered through the TinyMCE WYSIWYG control. It's published (id=1119) and only has a text entry control. I just want to retrieve it from the database and display as text.

    Any idea's?

    Thanks!

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 12, 2018 @ 14:46
    Dave Woestenborghs
    0

    Hi,

    Seeing your question it seems to me you are new to Umbraco.

    So it would be best to start with a simple tutorial like this one :

    https://our.umbraco.com/documentation/Tutorials/Creating-Basic-Site/

    You can also watch the video's created by Paul Seal : https://www.youtube.com/watch?v=VWy2HlRDCRM&list=PL90L_HquhD--OWQNLyO1-KRxVDd0NPBfZ

    https://www.youtube.com/watch?v=ttWuV88OJfM&list=PL90LHquhD-Wu55PJ9N8mZ6Lh5Rhy0X6

    Or take some of the free video's on Umbraco.tv

    https://umbraco.tv/videos/umbraco-v7/

    Dave

  • LeadMagnet 7 posts 76 karma points
    Oct 15, 2018 @ 11:39
    LeadMagnet
    0

    Thank you for the reply, albeit relatively unhelpful.

    Fully agree on Paul's YT videos! Amazing content and a must for anyone just starting out. Been a subscriber of his for years.

    My problem ended up being a database error. The content ID I was after (1119) was actually 1118 on my test rig. How my live and test machines have gotten out of sync is a mystery, quickly solved by a full restore. I figured this out by directly querying the database "cmsContentXml" table to just get the content I wanted.

    Once I figured this out using the following worked a treat:

        <p>
            @{  var page = Umbraco.Content(1118); }
            @page.ContentBody
        </p>
    

    The property of the content I need is named "ContentBody".

    As for UmbracoTV, paying for (what turned out to be) 2 lines of code would have really made me mad! Anyway, problem solved.

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft