Using RenderMvcController and getting error "Cannot bind source content type"
Hi all,
I'm trying to setup a RenderMvcController in v8.6.3 (Something I've done in V7 many times) and getting the following error "Cannot bind source content type Umbraco.Web.PublishedModels.EventPage to model type Example.Models.EventPageViewModel.". I have followed this https://our.umbraco.com/Documentation/Reference/Routing/custom-controllers trying both the "PublishedContentWrapped" and the model builder method which gives the error above. Please find my code below:-
Controller
using System;
using System.Web.Mvc;
using Example.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
namespace Example.Controllers.RenderMvc
{
public class EventPageController : RenderMvcController
{
public override ActionResult Index(ContentModel model)
{
var pageModel = new EventPageViewModel(model.Content);
pageModel.Testing = "Test";
return CurrentTemplate(model);
}
}
}
Model
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.PublishedModels;
namespace Example.Models
{
public class EventPageViewModel : EventPage
{
public EventPageViewModel(IPublishedContent content) : base(content) { }
public string Testing { get; set; }
}
}
if it's any consolation, when running the official training courses... at least a quarter of the class would do this each time in the Route Hijacking exercise...
so my radar is still slightly attuned to spotting it!
and it's a dead easy thing to muck up from time to time... (in V7 and V8)
Using RenderMvcController and getting error "Cannot bind source content type"
Hi all,
I'm trying to setup a RenderMvcController in v8.6.3 (Something I've done in V7 many times) and getting the following error "Cannot bind source content type Umbraco.Web.PublishedModels.EventPage to model type Example.Models.EventPageViewModel.". I have followed this https://our.umbraco.com/Documentation/Reference/Routing/custom-controllers trying both the "PublishedContentWrapped" and the model builder method which gives the error above. Please find my code below:-
Controller
Model
View
Any help would be much appreciated feels like I'm going round in circles
Cheers, James
Hi James
Would returning the 'PageModel' to the CurrentTemplate make all the difference here?
eg:
Looks like your View is expecting a model of type EventPageViewModel but you are sending it a model of type 'ContentModel' :-P
regards
Marc
Ouch, yep you're spot on. I would say the heat got me but the air conditioning is on :-P.
Thanks a lot, James
hehe
if it's any consolation, when running the official training courses... at least a quarter of the class would do this each time in the Route Hijacking exercise...
so my radar is still slightly attuned to spotting it!
and it's a dead easy thing to muck up from time to time... (in V7 and V8)
regards
Marc
is working on a reply...