Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I'm struggling here on a piece of Razor code:
I have a StaffItem document type
A StaffItem document type has a property, staffCourses, of type MNTP
Now in in Razor, in a foreach loop through my staff members, I'm trying to list all courses (selected with MNTP) for a staffmember.
@if (item.HasValue("staffCourses"))
{
<p><strong>Courses</strong></p>
foreach (var course in item.staffCourses)
... print courses
}
The problem is I can't loop through the staffCourses for my StaffItem. VS Intellisense tells me:
"umbraco.MacroEngine.DynamicNode doesn't contain a definition for "staffCourses" ..."
How can I access the MNTP values on my StaffItem doctype ?
Thanks for your help,
Anthony
Hi Anthony,
Try this instead
if(f.GetProperty("staffCourses").Value !=null && f.Has("staffCourses")){}
found the issue,
The problem was that I defined my collection of staffItem objects as a DynamicNodeList
DynamicNodeList categorieItems = new DynamicNodeList();
...
foreach (var category in categories) { categorieItems = @Model.AncestorOrSelf("StaffArea").Children.Where("categoryStaff == \"" + category + "\""); }
I changed my categoryItems to:
var categorieItems = @Model.AncestorOrSelf("StaffArea")
.Children.Where("categoryStaff == \"" + category + "\"");
And now I can loop through the staffCourses on a staffItem like this:
Don't know why I keep using this DynamicNodeList, it gives me nothing but trouble.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
accessing MNTP items with Razor
Hi,
I'm struggling here on a piece of Razor code:
I have a StaffItem document type
A StaffItem document type has a property, staffCourses, of type MNTP
Now in in Razor, in a foreach loop through my staff members, I'm trying to list all courses (selected with MNTP) for a staffmember.
@if (item.HasValue("staffCourses"))
{
<p><strong>Courses</strong></p>
foreach (var course in item.staffCourses)
{
... print courses
}
}
The problem is I can't loop through the staffCourses for my StaffItem. VS Intellisense tells me:
"umbraco.MacroEngine.DynamicNode doesn't contain a definition for "staffCourses" ..."
How can I access the MNTP values on my StaffItem doctype ?
Thanks for your help,
Anthony
Hi Anthony,
Try this instead
found the issue,
The problem was that I defined my collection of staffItem objects as a DynamicNodeList
...
I changed my categoryItems to:
var categorieItems = @Model.AncestorOrSelf("StaffArea")
.Children.Where("categoryStaff == \"" + category + "\"");
And now I can loop through the staffCourses on a staffItem like this:
@if (item.HasValue("staffCourses"))
{
<p><strong>Courses</strong></p>
foreach (var course in item.staffCourses)
{
...
}
}
Don't know why I keep using this DynamicNodeList, it gives me nothing but trouble.
is working on a reply...