Copied to clipboard

Flag this post as spam?

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


  • Harry Spyrou 212 posts 604 karma points
    Sep 03, 2018 @ 09:30
    Harry Spyrou
    0

    Nested Content in an ajax call

    Hello,

    I'm trying to get a nested content collection in a partial with an ajax call like this (the call works fine, ignore the success I haven't reached that point yet):

     $(".clearAll-desktop").click(function () {
            event.preventDefault;
            var pageId = $(".curtains-module").attr('id');
            console.log(pageId);
            $.ajax({
                url: '/umbraco/Surface/CurtainsModuleSurface/GetFabrics',
                type: 'POST',
                data: { data: pageId },
                dataType: 'string',
                success: function (data1) {
                    console.log('success');
                }
            });
            return false;
        })
    

    The controller(here's where the problem lies):

        namespace MyNameSpace.Web.Controllers.Surface
    {
        public class CurtainsModuleSurfaceController : BaseSurfaceController
        {
    
            [HttpPost]
            public JsonResult GetFabrics(int data)
            {
                var page = Umbraco.TypedContent(data);//this returns the id correctly
                var fabricsCollection = page.GetPropertyValue<IEnumerable<IPublishedContent>>("fabricsCollection"); //fabrics collection returns null
                return Json(fabricsCollection);
            }
        }
    }
    

    The main view is rendered like this:

    @foreach (var item in Model.GetPropertyValue<IEnumerable<IPublishedContent>>("generalContentCollection"))
    {
        var partialViewName = "_" + item.DocumentTypeAlias;
      if (partialViewName == "_curtainsModule")
       {
            Html.RenderPartial("CurtainsModule", new CurtainsModuleModel(Model, item));
        }
        else
        {
            @Html.Partial(partialViewName, item);
        }
    }
    

    So, basically the fabricsCollection is a nested content collection deep inside another nested content collection. However, when I try to get it from the page (the controller is the problem here) it returns null. I'm not sure why, would someone be able to help?

    Thanks in advance, Harry

  • Harry Spyrou 212 posts 604 karma points
    Sep 03, 2018 @ 10:41
    Harry Spyrou
    0

    I'm kind of running out of time and can't get a solution. If anyone could help even a little bit I'd really appreciate it.

Please Sign in or register to post replies

Write your reply to:

Draft