Copied to clipboard

Flag this post as spam?

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


  • Andrei 2 posts 32 karma points
    Feb 07, 2013 @ 09:26
    Andrei
    0

    Configuring Template to Render Property Using Razor

    Hello - basic question here, looking for best practice suggestions.

    I have a standard TextPage with a "bodyText" property. What is the recommended way to write the Razor code in my template so it renders the text entered into bodyText box? 

    I got it to work by inserting a page field:

    @Umbraco.Field("bodyText")

    But as I'm doing some reading it seems that is the wrong way to go about it and I should be inserting this script:

    @Model.bodyText 

    But the above does not render my bodyText property and I get a compilation error:

    'Umbraco.Web.Models.RenderModel' does not contain a definition for 'bodyText' and no extension method 'bodyText' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)

    Thanks in advance!

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 07, 2013 @ 12:20
    Jeroen Breuer
    100

    You could do this:

    //Strongly Typed
    @Model.Content.GetPropertyValue<IHtmlString>("bodyText");
    //Dynamic
    @CurrentPage.bodyText 

    More info here: 

    http://our.umbraco.org/documentation/Reference/Mvc/views

    http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx

    Jeroen

  • Andrei 2 posts 32 karma points
    Feb 08, 2013 @ 06:21
    Andrei
    0

    Cheers for the examples and links Jeroen!

Please Sign in or register to post replies

Write your reply to:

Draft