Arukala
Arukala

Reputation: 11

How to ge the field set values of Archetype datatype using Partial views Umbraco?

I am getting "Object reference not set to an instance of an object" exception when using the following code in Partial views section but same code working fine in Templates. Didn't understand why ?

Upvotes: 0

Views: 214

Answers (1)

Jabberwocky
Jabberwocky

Reputation: 789

That's a really general question. If you follow the Archetype documentation you won't have a problem getting the values.

Two things: "Not set to an instance of an object" means that you literally have asked something that doesn't exist. I've came across this error so many times and every time was the fact that my path (e.g. your Model.Content in this case) is wrong. Maybe your editor is in another node or a parent or a descendant etc etc.

Second is: don't let razor 'guess' the type of value you need. Instead of

Model.Content.GetPropertyValue("example")

Try either: Model.Content.GetPropertyValue<string>("example") Or: Model.Content.GetPropertyValue<int>("example")

That way, you won't be making mistakes when for example you ask for an int, but razor 'guesses' by itself you're asking for a string. Even if your path is correct, that might mess your code up.

However, first check your path. "Not set to an instance of an object" usually means that you're asking for something that's not there. Different path needed most probably.

Upvotes: 1

Related Questions