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
    5 days ago
    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) { }
    
Please Sign in or register to post replies

Write your reply to:

Draft