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);
}
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?
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."
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..
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? :)
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 :)
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 )
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!
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 ..?
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.
Cannot bind source type... to model type Umbraco.Core.Models.PublishedContent.IPublishedContent.
Hi, is anybody out there to help me w/ it ?..
Model:
Controller:
View:
I want to bang my head against the wall.. mb im just dumb ?
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
?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."
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..
You shouldn't need
IPublishedContent
in your model, nope. On my controllers I usereturn CurrentTemplate(viewModel)
instead ofreturn View(viewModel)
and it's working; could we try that next? :)The problem is its only available, if u're inherit from RenderMvcController, not Surface Controller.
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 :)
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 )
I would suggest having two controllers - A RenderMvcController that handles the page routing and a SurfaceController that handles the form submission.
Hah, the other template is now dead cuz too, i removed IPublishedContent, its still not working though..
Model:
2 same controllers ( cuz deleted submit method on download controller ):
Is it the same error?
yeah
are u still here.. ?
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!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 ..?
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.
is working on a reply...