-1

Here is part of my code:

@using Umbraco.Web;
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

@{
    var mTest = Model.Content.GetPropertyValue<string>("info", true);
}
<div>
    @mTest
</div>

It is impossible to get the content of info property. I am getting the following error: Object reference not set to an instance of an object. From the other side, everything works fine by using:

@Umbraco.Field("info", recursive: true)

However, I want to use the first approach. I'd appreciate any help on that.

Unknown developer
  • 5,414
  • 13
  • 52
  • 100
  • I don't see anything wrong with your code. If you try to output `@Model.Content` do you get an object reference as well? – Mark Mar 11 '18 at 08:26
  • I also agree w/ mark that there's nothing wrong with your code. The only thing I can think of is that the particular record your testing doesn't exist. – Napoli Mar 12 '18 at 12:20

1 Answers1

0

I believe the error.

Model.Content is the same as Currentpage . My guess and I believe it is a good one is that the value you're looking for is not on the current page but maybe in a master page/child/ancestor/parent.

I think what you need is to traverse through the 'family' of nodes and find that value. If you had that value on the home page for example and you wanted it to show on a child page:

Model.Content.Ancestor(1).GetPropertyValue("info");

This is just an example. I can't tell a lot on what you're trying to do from what you said already. As others have commented, your code seems fine.

Jabberwocky
  • 768
  • 7
  • 18