Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
175 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...