Just upgraded a site to 7.6.3 (from 7.4.1) and recoding views and partials to use ModelsBuilder.
I have a partial that puts out a list of news articles picked using an MNTP. However, can't get it to work using the documented method.
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
@{
if (Model.HasValue("articleList")) {
var articleList = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("articleList");
foreach (var article in articleList) {
Some more code
}
}
}
I get a YSOD saying Object reference not set to an instance of an object. on the foreach line.
I don't know if I am right, but
I believe you've to use Model.Content.HasValue or Model.Content.GetProperty.
As for the article in the articleList, if articleList are children of the Model.Content, I normally check if the Model.Content.Children are greater than 0.
if (Model.Content.Children.Count() > 0)
{
foreach (var article in Model.Content.ChildrenAsList)
{
}
}
When using UmbracoViewPage, the Model doesn't have a .Content. So it all appears to work above the foreach line, but I'm suspecting some issue with the built-in property value converters which is why it's complaining.
Typed MuliNodeTreePicker in Partial View
Umb 7.6.3
Just upgraded a site to 7.6.3 (from 7.4.1) and recoding views and partials to use ModelsBuilder.
I have a partial that puts out a list of news articles picked using an MNTP. However, can't get it to work using the documented method.
I get a YSOD saying
Object reference not set to an instance of an object.
on the foreach line.The page that invokes this uses:-
and
The master page uses:
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
I'm a fan of ViewPage rather than TemplatePage ;)
Any advice appreciated.
-Craig
I don't know if I am right, but I believe you've to use Model.Content.HasValue or Model.Content.GetProperty.
As for the article in the articleList, if articleList are children of the Model.Content, I normally check if the Model.Content.Children are greater than 0.
Hi Victor,
When using UmbracoViewPage, the Model doesn't have a .Content. So it all appears to work above the foreach line, but I'm suspecting some issue with the built-in property value converters which is why it's complaining.
Ouch,
Turns out the MNTP in 7.6.3 is a different beast to the one in 7.4.1. I deleted it and reinstated using the new datatype and all is now working!
Painful.
is working on a reply...