Copied to clipboard

Flag this post as spam?

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


  • Sameer 6 posts 88 karma points
    Aug 22, 2016 @ 06:27
    Sameer
    0

    'YouTube.Models.YouTube' does not contain a definition for 'Id'

    I am new to Umbraco and razor syntax. I am sorry if this issue is already discussed.

    I am using a partial view in which I want to display the videos I am using the following query to get videos:

        @using YouTube.Models
        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
        @{
            var homePage = CurrentPage.AncestorsOrSelf(1).First();  
            var lectureVideos = homePage.Descendants("videoLecture").Where("Visible");
        }
    
    @foreach (var lecture in lectureVideos)
    {               
        var typedVideo = lecture.GetPropertyValue<YouTube>("youTubeVideos");
        var videoId = typedVideo.Id;
        var videoUrl = String.Format("https://www.youtube.com/watch?v={0}", videoId);             
    }
    

    It gives the following error message:

    'YouTube.Models.YouTube' does not contain a definition for 'Id'

    Line 14:    var typedVideo = lecture.GetPropertyValue<YouTube>("youTubeVideos");
    Line 15:    var videoId = typedVideo.Id;
    Line 16:    var videoUrl =String.Format("https://www.youtube.com/watch?v={0}", videoId);
    Line 17:    <p>@lecture.youTubeVideos</p>   
    

    can someone please help me to resolve this, or guide me how to display Youtube videos in this page.

    Thanks in advance

  • Michael Biggs 18 posts 98 karma points
    Aug 22, 2016 @ 12:59
    Michael Biggs
    0

    When your casting to a YouTube object your calling for a ID on a IEnumerable. Trying calling .First() then getting the ID.

  • Sameer 6 posts 88 karma points
    Aug 22, 2016 @ 13:18
    Sameer
    0

    Thanks for your reply, I have tried and resolved it, not sure if it's a better approach.

    @foreach (var lecture in lectureVideos)
    {       
        var VideoModel = lecture.GetPropertyValue<YouTube>("youTubeVideos");
        var VideosList = VideoModel.GetEnumerator();
            VideosList.MoveNext();
        var typedVideo = VideosList.Current;            
        var videoId = typedVideo.Id;
        var videoUrl = String.Format("https://www.youtube.com/watch?v={0}", videoId);   
    }
    

    Please share if you have better solution for this, Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft