Copied to clipboard

Flag this post as spam?

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


  • Ryan Carlin 1 post 71 karma points
    Dec 04, 2019 @ 16:29
    Ryan Carlin
    0

    Cannot return the IPublishedContent because the UmbracoHelper was not constructed with an IPublishedContent

    I have the below surface controller that has an Ajax call from the UI but when it tries to instantiate the SelectViewModel() it is giving me an error with the UmbracoHelper.

    "System.InvalidOperationException: 'Cannot return the IPublishedContent because the UmbracoHelper was not constructed with an IPublishedContent.'"

    Am I supposed to instantiate the UmbracoHelper again or can I not create ViewModelObjects within an Ajax call? Any help appreciated.

    public class SelectSurfaceController : BaseSurfaceController
    {
        [HttpGet]
        public ActionResult TravellersTemplate(int count)
        {
            var model = new SelectViewModel();
            model.TravellersDatesOfBirth = Enumerable.Range(1, count).Select(x => new DateTime()).ToList();
    
            return PartialView("_Travellers", model);
        }
    
    
    
    public class SelectViewModel : LayoutViewModel
    {
        public SelectViewModel() : base(Current.UmbracoHelper.AssignedContentItem) { }        
        public SelectViewModel(IPublishedContent content) : base(content) { }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies