Copied to clipboard

Flag this post as spam?

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


  • Babaso Mahadik 2 posts 72 karma points
    Mar 30, 2020 @ 11:34
    Babaso Mahadik
    0

    Getting error while accessing Value from Model i.e Model.Value

    'IPublishedContent' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'IPublishedContent' could be found

    example :

    var title = Model.HasValue(alias: "title") ? Model.Value

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Mar 31, 2020 @ 06:10
    Marc Goodson
    0

    Hi Babaso

    Which version of Umbraco are you using?

    The syntax you've posted above is the new syntax in Umbraco V8 - but noticed that you have selected V7 when posting the question... anyway if you are running V7 the syntax would be:

    var title = Model.Content.HasValue("title") ? Model.Content.GetPropertyValue<string>("title") : Model.Content.Name;
    

    If you are running V8 then it would be:

    var title = Model.HasValue("title") ? Model.Value<string>("title") : Model.Name;
    

    regards

    Marc

  • Babaso Mahadik 2 posts 72 karma points
    Mar 31, 2020 @ 07:00
    Babaso Mahadik
    0

    Thanks Marc, Yes, I am using Umbraco 7 and above syntax wont work.

    Instead, I have used below syntax and its worked.

    One way : Model.Title

    Second way : Model.GetPropertyValue("title")

    Thank you

Please Sign in or register to post replies

Write your reply to:

Draft