Copied to clipboard

Flag this post as spam?

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


  • Allie 26 posts 116 karma points
    Sep 30, 2021 @ 16:16
    Allie
    0

    Cannot bind source type... to model type Umbraco.Core.Models.PublishedContent.IPublishedContent.

    Hi, is anybody out there to help me w/ it ?..

    Model:

     public class DownloadsViewModel : PublishedContentWrapped
    {
        public DownloadsViewModel(IPublishedContent content) : base(content) { }
        public List<DownloadCategory> DownloadCategories { get; set; } = new List<DownloadCategory>();
    }
    

    Controller:

    public readonly IDownloadManager _downloadManager;
        public readonly ILogManager _logManager;
        public DownloadSurfaceController(IDownloadManager downloadManager, ILogManager logManager)
        {
            _downloadManager = downloadManager;
            _logManager = logManager;
        }
    
        // get: /download/
        public ActionResult Index(ContentModel model)
        {
            List<DownloadCategory> downloadCategories = _downloadManager.GetManagedFiles();
    
            DownloadsViewModel downloadsViewModel = new DownloadsViewModel(model.Content) { DownloadCategories = downloadCategories };
    
            return View(downloadsViewModel);
        }
    

    View:

      @inherits Umbraco.Web.Mvc.UmbracoViewPage<DownloadsViewModel>
    
    @{
        Layout = "master.cshtml";
    }
    

    I want to bang my head against the wall.. mb im just dumb ?

  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Sep 30, 2021 @ 17:04
    Janae Cram
    3

    What is the name of your document type? If I remember right, your controller name and your document type name need to be the same as that's how it's finding the route. I don't think you want the word "Surface" in there in this case if it's not in the document type name.

    Can you try it making sure it's named DocumentTypeNameController?

  • Allie 26 posts 116 karma points
    Sep 30, 2021 @ 17:28
    Allie
    0

    So, i renamed it to DownloadController and now getting "Cannot bind source content type Umbraco.Web.PublishedModels.Download to model type Models.DownloadsViewModel. The source is a ModelsBuilder type, but the view model is not. The application is in an unstable state and should be restarted."

  • Allie 26 posts 116 karma points
    Sep 30, 2021 @ 17:35
    Allie
    0

    Or im just getting "Cannot bind source type HH.CustomerPortal.Web.Models.DownloadsViewModel to model type Umbraco.Core.Models.PublishedContent.IPublishedContent." I dont get it, do i need this 'IPublishedContent' in my model or not..

  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Sep 30, 2021 @ 17:40
    Janae Cram
    1

    You shouldn't need IPublishedContent in your model, nope. On my controllers I use return CurrentTemplate(viewModel) instead of return View(viewModel) and it's working; could we try that next? :)

  • Allie 26 posts 116 karma points
    Sep 30, 2021 @ 17:44
    Allie
    0

    The problem is its only available, if u're inherit from RenderMvcController, not Surface Controller.

  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Sep 30, 2021 @ 17:45
    Janae Cram
    1

    Yep, to render the template you'll want to inherit from RenderMvcController instead of SurfaceController as that's part of how it's doing the routing :)

  • Allie 26 posts 116 karma points
    Sep 30, 2021 @ 17:47
    Allie
    0

    If I remember right, i cant use return RedirectToCurrentUmbracoPage() or return CurrentUmbracoPage().., if inheriting from RenderMvcController, so.. how we can go with it ? ( these are needed in my another 'submit' method )

  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Sep 30, 2021 @ 17:50
    Janae Cram
    1

    I would suggest having two controllers - A RenderMvcController that handles the page routing and a SurfaceController that handles the form submission.

  • Allie 26 posts 116 karma points
    Sep 30, 2021 @ 18:09
    Allie
    0

    Hah, the other template is now dead cuz too, i removed IPublishedContent, its still not working though..

    Model:

     public class DownloadsViewModel 
        {
            public List<DownloadCategory> DownloadCategories { get; set; } = new List<DownloadCategory>();
        }
    

    2 same controllers ( cuz deleted submit method on download controller ):

    public class DownloadsController : Umbraco.Web.Mvc.RenderMvcController
        {
            private IDownloadManager _downloadManager;
    
            public DownloadsController(IDownloadManager downloadManager)
            {
                _downloadManager = downloadManager;
            }
            public override ActionResult Index(ContentModel model)
            {
                List<DownloadCategory> downloadCategories = _downloadManager.GetManagedFiles();
    
                DownloadsViewModel downloadsViewModel = new DownloadsViewModel() { DownloadCategories = downloadCategories };   
    
                return CurrentTemplate(downloadsViewModel);
            }
        }
    
  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Sep 30, 2021 @ 18:33
    Janae Cram
    100

    Is it the same error?

  • Allie 26 posts 116 karma points
    Sep 30, 2021 @ 18:37
    Allie
    0

    yeah

  • Allie 26 posts 116 karma points
    Sep 30, 2021 @ 18:58
    Allie
    0

    are u still here.. ?

  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Sep 30, 2021 @ 19:31
    Janae Cram
    100

    I'm trying to think through the different potential issues this could be and go through the list! The next thing that I think could be the issue that I would try is potentially to remove the master layout and see if it works without it.

    If the Master layout is using IPublishedContent then you'll need your new model to inherit from it, and that may be the problem? Removing the layout at least allows us to test it!

  • Allie 26 posts 116 karma points
    Sep 30, 2021 @ 19:59
    Allie
    0

    Fine, so i removed all the IPublishedContent ( from my model that im using in tempates and from Master layouts ). Only one is working dont no why. Can it be because im using the same model in 2 views or ..?

  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Sep 30, 2021 @ 20:01
    Janae Cram
    0

    If the one that is working is the same two models, then that is likely it, yes. Your master template would need to be using a model that your templates beneath it can inherit - you can use IPublishedContent for that or have your own custom model on the master that your other pages' models inherit from. That way it won't be trying to bind two incompatible models - one to your master, and one to the specific template.

Please Sign in or register to post replies

Write your reply to:

Draft