Copied to clipboard

Flag this post as spam?

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


  • Michael Beever 74 posts 155 karma points
    Aug 12, 2020 @ 12:56
    Michael Beever
    0

    Nested Content from another page

    Hello,

    I have a page with forms on and I need to use the same page content elsewhere on the site.

    I have managed to get the nested to work but then try and put the Form PDF URL in and it stops working. I am using the same process for images and they are working as expected.

     @{
    
    var FormPage = Umbraco.Content(2151);
    
    var PDFImage = FormPage.FormPDFIcon;
    var XLSImage = FormPage.FormXLSIcon;
    
    var DownloadForms = FormPage.downloadableFormsNested;
    
    var MouseOver = "";
    
    
    
                foreach(var item in DownloadForms)
                {
    
                   var FormLink = item.GetPropertyValue<IPublishedContent>("FormURL");
                    var FormTitle = item.GetPropertyValue("FormTitle");
                    var FormDate = item.GetPropertyValue<DateTime>("FormDate");
                    var FormImg = item.GetPropertyValue<IPublishedContent>("FormImg");
    
    
    
                    string ext = Path.GetExtension(@FormLink.Url);
    
                    switch (@ext)
                        {
                         case ".pdf":
                             MouseOver = @PDFImage.Url;
                            break;
                         case ".xls":
                            MouseOver = @XLSImage.Url;
                            break;
                        }
    
                     <div class="col-sm-3 border">
                        <center>
    
                               <a href="@item.FormLink.Url" target="_blank">
                               <p>@item.FormTitle</p>
                               <img src="@item.FormImg.Url"> 
                               <p>Form Date: @item.FormDate.ToString("MMM yyyy")</p></a>
    
                        </center>
                    </div>                   
    
                }
    
    }
    

    Error I get is:

    'Umbraco.Web.PublishedContentModels.DownloadForms' does not contain a definition for 'GetPropertyValue' Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.PublishedContentModels.DownloadForms' does not contain a definition for 'GetPropertyValue'

    Source Error:

    Line 107: { Line 108:
    Line 109: var FormLink = item.GetPropertyValue

  • Michael Beever 74 posts 155 karma points
    Aug 12, 2020 @ 14:03
    Michael Beever
    0

    Changed the code slightly.

                    foreach(var item in DownloadForms)
                {
    
    
                   @* var FormTitle = item.GetPropertyValue("FormTitle");
                    var FormDate = item.GetPropertyValue<DateTime>("FormDate");
                    var FormImg = item.GetPropertyValue<IPublishedContent>("FormImg");
    
    
    
                    string ext = Path.GetExtension(@FormLink.Url);
    
                    switch (@ext)
                        {
                         case ".pdf":
                             MouseOver = @PDFImage.Url;
                            break;
                         case ".xls":
                            MouseOver = @XLSImage.Url;
                            break;
                        }
                       *@
                     <div class="col-sm-3 border">
                        <center>
    
                               <a href="@item.FormURL.Url" target="_blank">
                               <p>@item.FormTitle</p>
                               <img src="@item.FormImg.Url"> 
                               <p>Form Date: @item.FormDate.ToString("MMM yyyy")</p></a>
    
                        </center>
                    </div>                   
    
                }
    
    }
    

    Now i get the error saying FormURL does not exist when it clearly does and not sure why this will not bring content through.

    Here is the URL to the page with the code working without the FormURL in it. https://xpsbridge.sail-dev.com/lgps-members/forms-and-guides/forms/

  • David Armitage 505 posts 2073 karma points
    Aug 13, 2020 @ 04:56
    David Armitage
    0

    I sit Umbraco 7 or 8?

    If its Umbraoc 8 the correct code should be something like this.

    item.Value<DateTime>("FormDate")
    

    I would also put an if statement around the link to check to see if that isn't null.

    if(item.FormURL != null)
    {
     <img src="@item.FormImg.Url"> 
    }
    

    Regards

    David

  • Michael Beever 74 posts 155 karma points
    Aug 13, 2020 @ 06:36
    Michael Beever
    0

    Hi David,

    It's Umbraco 7.

    It does not appear to be the GetPropertyValue.

    It appears that the FormURL does not transfer into this nested item.

  • David Armitage 505 posts 2073 karma points
    Aug 13, 2020 @ 06:44
    David Armitage
    0

    Hi Michael,

    If the FormImg is an Image datatype.

    And you have checked if that isn't null (double check in quick watch)

    And this still doesn't have a URL.

    Then the only time I have seen this issue is if the physical file has been deleted. So umbraco still things the data item exists but cant find a related file. I had the exact same issue before and it was driving me crazy.

    If this sounds like the case then I would upload a new image from fresh then re select this new image in the backend. Save and Publish. Then test again in the frontend.

    Regards

    David

  • Michael Beever 74 posts 155 karma points
    Aug 13, 2020 @ 06:48
    Michael Beever
    0

    Hi David,

    It's not an image its a file name.

    It works on this page: https://xpsbridge.sail-dev.com/lgps-employers/forms/

    But this page won't render the FormURL

    https://xpsbridge.sail-dev.com/lgps-members/forms-and-guides/forms/

  • David Armitage 505 posts 2073 karma points
    Aug 13, 2020 @ 06:53
    David Armitage
    0

    Ok so its this line of code?

    @item.FormURL.Url

    So what datatype is FormURL?

  • Michael Beever 74 posts 155 karma points
    Aug 13, 2020 @ 06:54
    Michael Beever
    0

    same as form img a media picker

  • David Armitage 505 posts 2073 karma points
    Aug 13, 2020 @ 07:06
    David Armitage
    0

    Ok so the same. Check that the physical file exists. My guess is you dont have the physical file on your machine.

    This happens maybe if you have downloaded the live site locally and didn't pull down all the media. My guess is that specific media file has been lost somewhere.

    I would test re-uploading the file through Umbraco backend and then re selecting the file on that item.

    Then test again. My guess is it will then work.

  • Michael Beever 74 posts 155 karma points
    Aug 13, 2020 @ 07:07
    Michael Beever
    0

    Still on the same machine sadly.

    The Files work on the first page but not when I have linked across

  • David Armitage 505 posts 2073 karma points
    Aug 13, 2020 @ 07:12
    David Armitage
    0

    I have never had problems with nested content displaying either images or documents.

    So I highly doubt nested content is the blame.

  • Michael Beever 74 posts 155 karma points
    Aug 13, 2020 @ 07:15
    Michael Beever
    0

    I think it is how i am bringing the Nested content into the page that is causing more of the issue.

  • Michael Beever 74 posts 155 karma points
    Aug 13, 2020 @ 11:43
    Michael Beever
    0

    Hi David,

    Here is how I am pulling the nested content from.

    var DownloadForms = FormPage.downloadableFormsNested;
    

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.PublishedContentModels.DownloadForms' does not contain a definition for 'FormURL'

    Source Error:

    Line 104: Line 105: foreach(var item in DownloadForms) Line 106: { Line 107:
    Line 108:

    Source File: D:\XPSBridge\Views\FormDisplayPage.cshtml Line: 106

    Stack Trace:

    [RuntimeBinderException: 'Umbraco.Web.PublishedContentModels.DownloadForms' does not contain a definition for 'FormURL']

  • David Armitage 505 posts 2073 karma points
    Aug 13, 2020 @ 14:19
    David Armitage
    0

    I just had another thought since I saw your post on Facebook.

    Regarding your comment...

    All of the items work except FormURL it says it cannot be found. It is a media picker. I have two of these in the nested item and the second one works as expected.

    If one is working and the other isn't. I am thinking is the second (the one not working) a new field you have added? If so are you using models builder or something like that and forgot to re-build the models?

    Also what I would try if you dont have a lot of data and happy to fix the data up afterwards.

    Try removing the field from the doc type so its full gone. Then add a new field. I would even go as far as giving it a different name. Then try and render this to the front-end like the working one.

    Something strange is going on and this could potentially either fix the problem or help you figure it out at least.

    Regards

    David

  • Michael Beever 74 posts 155 karma points
    Aug 13, 2020 @ 14:22
    Michael Beever
    0

    Hi David,

    Thanks for replying.

    The page that the content is edited on works fine.

    https://xpsbridge.sail-dev.com/lgps-employers/forms/

    I am then trying to replicate this page on another site so that the application Forms can be changed once.

    This is where the content is not working correctly.

  • David Armitage 505 posts 2073 karma points
    Aug 13, 2020 @ 14:21
    David Armitage
    0

    Actually I can see from your code you are not using models builder.

    I would still try removing the field and adding it again.

    Whey not add an extra field and leave that one as it is for the now to see if my ideas works first.

  • Michael Beever 74 posts 155 karma points
    Aug 13, 2020 @ 14:29
    Michael Beever
    0

    Umbraco confuses the hell out of me.

    That has worked. I have created a new media picker called FormLink and it works as I expected it to.

    What the .....

Please Sign in or register to post replies

Write your reply to:

Draft