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 am just learning Umbraco, and have been following the tutorials. I have setup my own document types, but essentially replaced the word 'Article' for 'Lesson' for my own purposes.
I am encountering an error when following this article
https://our.umbraco.com/documentation/Tutorials/Creating-Basic-Site/Articles-Parent-and-Article-Items
This is specifically in the razor code for the Partial view Macro File
The error is:
'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'lessonContents'
my code is:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{ var selection = Model.Content.Site().FirstChild("lessonsMain").Children("lesson") .Where(x => x.IsVisible()) .OrderBy("CreateDate desc"); }
@foreach(var item in selection){ <div class="article"> <div class="articletitle"><a href="@item.Url">@item.Name</a></div> <div class="articlepreview">@Umbraco.Truncate(@item.lessonContents,100) <a href="@item.Url">Read More..</a></div> </div> <hr/> }
I have a property in my Lesson document type named accordingly:
Can anyone point out where i may be going wrong?
TIA
Sarah
Hi Sarah
Welcome to our forum!!!
Try this code:
<div class="articlepreview">@Umbraco.Truncate(@item.GetPropertyValue<string>("lessonContents"),100) <a href="@item.Url">Read More..</a></div>
"item" is a PublishedContent class, you can't access property values just by property alias.
You have to use strongly typed models and models builder, read more - https://our.umbraco.com/documentation/reference/templating/modelsbuilder/
Or just use as I showed you "item" and GetPropertyValue("propertyAlias") method. Read more about Umbraco helper methods - https://our.umbraco.com/documentation/reference/querying/umbracohelper/
Post as many questions as you can and we will do great progress in Umbraco learning together with the community!
Thanks,
Alex
Thank you Alex,
I've just tried your code and it works perfectly!
I'll read the documentation links you've given me - I am really keen to learn Umbraco as I think it could be a fantastic tool.
Oh, and I will definitely be back here when I get stuck again ;-)
Thanks again,
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Noob Question - Partial View Macros
Hi,
I am just learning Umbraco, and have been following the tutorials. I have setup my own document types, but essentially replaced the word 'Article' for 'Lesson' for my own purposes.
I am encountering an error when following this article
https://our.umbraco.com/documentation/Tutorials/Creating-Basic-Site/Articles-Parent-and-Article-Items
This is specifically in the razor code for the Partial view Macro File
The error is:
'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'lessonContents'
my code is:
@{ var selection = Model.Content.Site().FirstChild("lessonsMain").Children("lesson") .Where(x => x.IsVisible()) .OrderBy("CreateDate desc"); }
I have a property in my Lesson document type named accordingly:
Can anyone point out where i may be going wrong?
TIA
Sarah
Hi Sarah
Welcome to our forum!!!
Try this code:
"item" is a PublishedContent class, you can't access property values just by property alias.
You have to use strongly typed models and models builder, read more - https://our.umbraco.com/documentation/reference/templating/modelsbuilder/
Or just use as I showed you "item" and GetPropertyValue("propertyAlias") method. Read more about Umbraco helper methods - https://our.umbraco.com/documentation/reference/querying/umbracohelper/
Post as many questions as you can and we will do great progress in Umbraco learning together with the community!
Thanks,
Alex
Thank you Alex,
I've just tried your code and it works perfectly!
I'll read the documentation links you've given me - I am really keen to learn Umbraco as I think it could be a fantastic tool.
Oh, and I will definitely be back here when I get stuck again ;-)
Thanks again,
Sarah
is working on a reply...