Copied to clipboard

Flag this post as spam?

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

  • Bram van den Bogaard 1 post 21 karma points
    6 days ago
    Bram van den Bogaard

    Getting parent properties in DocTypeGridEditorSurfaceController

    I'm currently using multiple DocTypeGridEditors that need to get properties from their parent node. To achieve this I'm using a DocTypeGridEditorSurfaceController.

    Unfortunately, while editing the DocTypeGridEditor the scope of the application changes and when pressing "submit" an error occurs because the Model of the parent can no longer be used. (AssignedContentItem returns null)

    Is there any way to get the parent items for the DocTypeGridEditor? I've tried using URL's, IContent, IPublishedContent, UnpublishedContent etc etc. but I have not found a way to get the correct properties.

    For reference, in the else-statement there is variable that gets the correct node with an hardcoded Id (which isn't good, there can be different Id's). When pressing "submit" the Id in AssignedContentItem is no longer 2306 but 2345.

    Any help would be appreciated because this is breaking my code right now.

    Edit: I'm beginning to believe that I've encountered some sort of bug. It cannot possibly be the case that it's completely impossible to get the ancestor for a DocTypeGridEditor, right ?

    public class ChaptersGridEditorSurfaceController : DocTypeGridEditorSurfaceController<ChaptersGridEditor>
        private readonly UmbracoHelper _umbracoHelper;
        private readonly IContentService _contentService;
        private readonly IUmbracoContextFactory _contextFactory;
        private readonly IUmbracoContextAccessor _umbracoContextAccessor;
        public ChaptersGridEditorSurfaceController(UmbracoHelper umbracoHelper, IContentService contentService, IUmbracoContextFactory contextFactory, IUmbracoContextAccessor umbracoContextAccessor)
            _umbracoHelper = umbracoHelper;
            _contentService = contentService;
            _contextFactory = contextFactory;
            _umbracoContextAccessor = umbracoContextAccessor;
        public ActionResult ChaptersGridEditor()
            using (var cref = _contextFactory.EnsureUmbracoContext())
                var pageId = _umbracoHelper.AssignedContentItem.Id;
                var page = _umbracoHelper.AssignedContentItem as Report;
                if (page != null)
                    Model.StartDate = page.StartDate;
                    Model.EndDate = page.EndDate;
                    var pageFromContentService = _contentService.GetById(pageId);
                    var x = _contentService.GetById(2306);
                    var startDate = pageFromContentService.GetValue<DateTime>("StartDate");
                    var endDate = pageFromContentService.GetValue<DateTime>("EndDate");
                return CurrentPartialView(Model);
Please Sign in or register to post replies

Write your reply to: