public class MyModel : RenderModel
{
public MyModel(IPublishedContent content, CultureInfo culture) : base(content, culture)
{
}
}
My Controller:
public override ActionResult Index(RenderModel model)
{
var myModel = new MyModel(model.Content, model.CurrentCulture);
return CurrentTemplate(myModel);
}
This is a copy-paste from another (working) PageTemplate/Controller/Model-set in my project, but I really cant see the difference.
(I had three similar page templates that didnt seem to need an document type (except for permissions to add it in the hierarchy), so I created one for my three page templates, so I was forced to use a dfferent name. This is corrected now and I will be using one DT for each PT)
Error : "Cannot bind source type Umbraco.Web.Models.RenderModel to MyModel"
I have a Page Template with the content below. When I visit the page I get the error
> Cannot bind source type Umbraco.Web.Models.RenderModel to MyModel
My Page Template:
MyModel looks like this
My Controller:
This is a copy-paste from another (working) PageTemplate/Controller/Model-set in my project, but I really cant see the difference.
Hi,
What model do you have set on your HomeMaster.cshtml ?
This is probably different
Dave
what do you mean by model? I have
in my HomeMaster.cshtml, so that should be RenderModel
The other page I have copy-pasted from had the same master page and that page works ok.
If I set
[at]inherits UmbracoViewPage[MyNameSpace.MyModel]
on my working page and visits the working page I get the same error message for that page.
I have also tried to set Layout = null;
Where did you store the Model cs file ? Is it in a seperate VS project ? Or is it placed in a App_Code folder ?
Dave
im placing in the app_code. and its not working
And what is the name of your controller ?
Dave
The MyModel.cs?
In [MyMVCProject]\ViewModels\
(the class is actually called MyViewModel )
(same VS-project as Umbraco, ie a plain MVC-project with Umbraco nuget-installation)
The controller is named
\Controllers\MyPageController.cs
and my page template is named \Views\MyPage.cshtml
Is your document type called "MyPage" ?
To do routehijacking the part before Controller needs to match your documenttype alias.
See the docs about that : https://our.umbraco.org/documentation/Reference/Routing/custom-controllers
Dave
SUPER!!!
Thanks! You saved my day :D
(I had three similar page templates that didnt seem to need an document type (except for permissions to add it in the hierarchy), so I created one for my three page templates, so I was forced to use a dfferent name. This is corrected now and I will be using one DT for each PT)
Nice to hear that the issue is solved. Don't forget to mark the topic as solved.
Dave
Saved my day too :)
Hmm. I though Id already done that. (When ypu wrote that post) Isnt it marked as solved?
is working on a reply...