Copied to clipboard

Flag this post as spam?

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


  • Thomas Kassos 54 posts 265 karma points
    Apr 27, 2019 @ 18:35
    Thomas Kassos
    0

    Umbraco.Field vs Model.Content.GetPropertyValue

    Hi guys, quick question,

    is there any difference in the performance between those 2?

    Umbraco.Field("alias") & Model.Content.GetPropertyValue("alias")

    Thanks in advance

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Apr 28, 2019 @ 08:14
    Marc Goodson
    3

    Hi Thomas

    Yes they are different! - but I'm not sure how quantifiably different their performance is!

    Umbraco.Field is a legacy approach for writing out property values, dictionary items, going way back before MVC was possible in Umbraco. It has lots of nice little helpers and falbacks for writing out property values, eg convertLineBreaks, removeParagraphTags, formatAsDate etc

    You can see how it's implemented here:

    https://github.com/umbraco/Umbraco-CMS/blob/v7/dev/src/Umbraco.Web/UmbracoComponentRenderer.cs#L223

    Whereas Model.Content.GetPropertyValue is just writing out the value of a property from the current page's IPublishedContent Model, introduced when Umbraco became more MVC like...

    https://github.com/umbraco/Umbraco-CMS/blob/v7/dev/src/Umbraco.Web/PublishedContentExtensions.cs#L274

    I'd expect Model.Content.GetPropertyValue to be quicker, but the best way to know would be to use the MiniProfiler to measure how each approach performs on your site:

    https://our.umbraco.com/documentation/Getting-Started/Code/Debugging/#miniprofiler

    regards

    Marc

  • Thomas Kassos 54 posts 265 karma points
    Apr 29, 2019 @ 10:37
    Thomas Kassos
    0

    Cheers Marc, I had no idea about the MiniProfiler, looks cool :)

  • 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