Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrew Unger 45 posts 148 karma points
    Mar 10, 2020 @ 19:53
    Andrew Unger
    0

    'Umbraco.Web.PublishedContentModels.ProductDocuments' does not contain a definition for 'GetPropertyValue' error message

    I am not sure why I get this error- "'Umbraco.Web.PublishedContentModels.ProductDocuments' does not contain a definition for 'GetPropertyValue'". I have used the same set up for other nested content on this page and it worked. If you have any insights on what might be wrong I would appreciate it.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
        var node = Model.Content;
        var home = node.Site();
        var productML = home.Descendant("markets");
        var product = @CurrentPage.Parent().Descendants("product").First();
    }
    
    
        @foreach(var stuff in product.Children.Where("Visible")){
                if (stuff.HasValue("relatedDocuments"))
                    {
                        foreach (var item in stuff.GetPropertyValue<IEnumerable<IPublishedContent>>("relatedDocuments"))
                        {
                            if (item.HasValue("documentFile") && item.HasValue("documentName"))
                            {
                                    var file = item.GetPropertyValue<IPublishedContent>("documentFile");
                                    <div class="boxspacenope">
                                    <div class="outline3">
                                        <div class="row">
                                            <div class="col s6 m6 l6" align="left">
                                                <div class="title3"><b>@item.GetPropertyValue("documentName")</b></div>
                                            </div>
                                            <div class="col s3 m3 l3" align="center">
                                            </div>
                                            <div class="col s3 m3 l3" align="center">
                                                <ul class="links">
                                                    <li>
                                                        <a href="@file.Url" target="_blank"><div class="underline">Download</div></a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            }
                        }
                    }
        }
    
  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Mar 11, 2020 @ 09:11
    Dave Woestenborghs
    0

    Hi Andrew,

    I think this caused because you are mixing dynamic and strongly typed syntax for accessing content.

    I wrote a article several years ago describing the difference between the two : https://24days.in/umbraco-cms/2015/strongly-typed-vs-dynamic-content-access/

    So if you change this line :

     var product = @CurrentPage.Parent().Descendants("product").First();
    

    To this :

     var product = Model.Content.Parent().Descendants("product").First();
    

    Your code will probably work

    Dave

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies