Copied to clipboard

Flag this post as spam?

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


  • John Lee 6 posts 116 karma points
    Aug 02, 2022 @ 09:51
    John Lee
    0

    Generated model throws NullReferenceException when text field is left blank

    I'm using ModelsBuilder in SourceCodeAuto mode, and I have a CMS property called pageHeading. (Umbraco V10.0.1)

    When I render pageHeading in my View all is good, until I clear the value of pageHeading in the CMS (ie. leave the field blank and publish). When I do that the GetPageHeading property in the auto-generated model throws a NullReferenceException when I call @Model.PageHeading in the View. So far I've noticed this problem with TextString and RTE fields.

    I don't think I'm doing anything out of the ordinary and I haven't encountered this in previous versions of Umbraco. I've tried switching on/off nullable reference types for the project, to no avail.

    Does anyone have any ideas as to what's causing this?

  • John Lee 6 posts 116 karma points
    Aug 03, 2022 @ 11:10
    John Lee
    100

    The issue was being caused by me overriding the constructor that's generated by modelsbuilder. I wasn't setting the local _publishedValueFallback field value, like the generated constructor was, so no fallback when the CMS field was left blank.

Please Sign in or register to post replies

Write your reply to:

Draft