Page with the data is not mapped to the base

Dec 18, 2014 at 3:04 AM
Edited Dec 18, 2014 at 3:07 AM
Hi,
I have service:
public class YouTubeService:IYouTubeService
    {
        public IList<YouTubeVideoObject> GetPlaylist()
        {
            return YouTubeVideoChannel.GetVideos();
        }
    }
And page
 public class YouTubePage:Webpage
    {
        public virtual IList<YouTubeVideoObject> Playlist { get; set; }
    }
How can I get data from YouTubeService in YouTubePage?
YouTubePage try to get items from db.
YouTubeVideoObject - not SiteEntity.
Coordinator
Dec 18, 2014 at 5:52 AM
Hi,

The way that you have written this, you're right it will try and treat YouTubeVideoObject as an associated entity.

To allow for additional data to be passed to the page, create an implementation of DocumentMetadataMap<YouTubePage>, and override the WebGetController (and WebGetAction if you want, although by convention it's Show if not overriden). From there you just need to create the appropriate controller, and and constructor injection you need to do will be done automatically. Then pass the Playlist data to ViewData/ViewBag/whatever works for you and deal with it in the page. There's an example of this in the articles app in the project with this document metadata map, controller, and view.

It's worth noting that you need to keep the YouTubePage (or whatever your given implementation of Webpage is at any time) as the primary model for the ViewResult, as this is used to resolve the View paths and select the correct Layout/Widgets/everything.

Hope this helps.
Marked as answer by burning1ife on 12/18/2014 at 6:26 AM
Dec 18, 2014 at 1:25 PM
Edited Dec 18, 2014 at 1:29 PM
Thanks. That's all I needed.
public class YouTubePageMetadata: DocumentMetadataMap<YouTubePage>
    {
        public override string WebGetController
        {
            get { return "YouTube"; }
        }
    }
public class YouTubeController : MrCMSAppUIController<YouTubeApp>
    {
        private readonly IYouTubeService _videoService;

        public YouTubeController(IYouTubeService videoService)
        {
            _videoService = videoService;
        }

        public ActionResult Show(YouTubePage page)
        {
            ViewData["playlist"] = _videoService.GetPlaylist();
            return View(page);
        }
    }
Coordinator
Dec 18, 2014 at 1:56 PM
Great. Please feel free to ask if you have any other issues.