Copied to clipboard

Flag this post as spam?

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


  • Aung Zin Phyo 17 posts 87 karma points
    Jan 08, 2020 @ 11:30
    Aung Zin Phyo
    0

    NestContent Get Data is always null in Surface Controller

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    using Umbraco.Core.Persistence;
    using Umbraco.Core.Composing;
    using CarRentalProject.Model;
    using NPoco;
    using Umbraco.Core.Services;
    using Umbraco.Core.Models.PublishedContent;
    using Umbraco.Core.Models;
    using Umbraco.Core;
    
    namespace CarRentalProject.Controllers
    {
    public class BookingSurfaceController : SurfaceController
    {
         public string test()
        {
            IContentService contentService = Services.ContentService;
    
            var content = contentService.GetById(1119);
            string CarRefName = content.GetValue("CarRefName").ToString();
            string VehecleNo = content.GetValue("VehecleNo").ToString();
    
            //Single media picker
            var image = content.GetValue("ChooseFeatureImage").ToString();
            var mediaItem = Umbraco.Media(image);
            var imgUrl = mediaItem.Url;
    
            //Multi media picker
            var typedMultiMediaPicker = content.GetValue("ChooseGalleryImage").ToString();
            List<string> tempMedia = typedMultiMediaPicker.Split(',').ToList();
            List<GalleryImage> GalleryImages = new List<GalleryImage>();
            foreach (var item in tempMedia)
            {
                GalleryImage galleryimg = new GalleryImage();
                var mediaItems = Umbraco.Media(item);
                var imgUrls = mediaItems.Url;
                galleryimg.ChooseGalleryImage = imgUrls;
    
                GalleryImages.Add(galleryimg);
            }
            //Add NestedContent Picker
            var nestedContent = content.GetValue<IEnumerable<IPublishedElement>>("CarDetails");
    
    
            //foreach (var item in tempNestedContent)
            //{
            //    string itemValue = item;
            //}
    
    
            return "success";
        }
    
    }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft