I have set up an Articulate Blog. Everything works just fine, seems to be a really well-built plugin :-)
The blog is in the root of the domain, and I would like to add a few menu items that are not part of the blog (like "About" and "Contact"). I have made a document type and a template for the "About"-page in the Umbraco backoffice, but I get this error:
"The
model item passed into the dictionary is of type
'Umbraco.Web.Models.RenderModel', but this dictionary requires a model
item of type 'Articulate.Models.IMasterModel'"
It sounds like you've copied and pasted markup in to your new Umbraco template instead of keeping the defaults. By default and Umbraco template will have:
@inherits Umbraco.Web.Mvc.UmbracoViewPage
You have:
@model Articulate.Models.IMasterModel
Which (as posted in the above article) is syntactic sugar for:
The problem with your custom page is that Umbraco passes in a model to your view of type RenderModel but your view is expecting a model of type IMasterModel, so that is why you are getting that exception.
So the first thing you can do is change @model Articulate.Models.IMasterModel back to what Umbraco's default is: @inherits Umbraco.Web.Mvc.UmbracoViewPage
However you will still have an issue because your layout page that you are using Layout = "~/App_Plugins/Articulate/Themes/Shazwazza/Views/Master.cshtml"; is also going to expect that it be given a model of type Articulate.Models.IMasterModel. The post referenced above also has information about that too and this all depends on if you need a layout page with a strongly typed model or not. There's no right answer to all of this, it really depends on how you structure your templates.
Ok, I'll try to explain this again. This is how MVC works, this is not an Articulate or Umbraco thing, it's just how ASP.Net MVC works.
Let say I have this, for example:
_MasterLayout.cshtml
BlogPage.cshtml
CustomPage.cshtml
BlogPage.cshtml might be of model type: IMasterModel. Now i can render anything in this view based on the model values.
CustomPage.cshtml might be of model type: MyCoolModel, Now i can render anything in this view based on the model values.
Both of these templates use the same layout: _MasterLayout.cshtml. The layout cannot be 2 different types of models at the same time, that is not possible. Therefore the _MasterLayout.cshtml would have to
have no model and not render anything in regards to the current model
have a model of dynamic
or a model that has a common base type between IMasterModel and MyCoolModel.
Taking this into account it should be pretty clear why this doesn't work on your master layout page:
var articulateMasterModel = Model as IMasterModel;
It will of course be null when rendering a non-articulate umbraco page because the model will be IPublishedContent.
Next, you need to know what things like @inherits Umbraco.Web.Mvc.UmbracoViewPage actually mean. I've mentioned this a few times in the link i posted earlier but will re-iterate again:
It is also important to know that in Articulate that all instances of IMasterModel are also IPublishedContent
Therefore, your master view that is shared with both articulate and regular Umbraco pages can have a model of IPublishedContent and you can use this model like you would normally in Umbraco.
I kind of understand what you are saying but still having issues.
My master page using this:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
This is required for things like:
@Umbraco.Field("...")
Your last sentence:
Therefore, your master view that is shared with both articulate and regular Umbraco pages can have a model of IPublishedContent and you can use this model like you would normally in Umbraco.
Seems to suggest that I should be able to use this model for a master page that is shared with both Articulate and my site's master page:
@Jeff, you are getting errors because you are using the wrong base classes.
This base class:
@inherits System.Web.Mvc.WebViewPage
is the MVC base class for views, this means it does not contain all of the Umbraco properties like @Umbraco @UmbracoContext, etc... This also means that it cannot process things like @Umbraco.Field because the property Umbraco does not exist on the class System.Web.Mvc.WebViewPage<T>. Does that make sense ?
The base class that we use by default for views is:
Umbraco.Web.Mvc.UmbracoTemplatePage which inherits from
Umbraco.Web.Mvc.UmbracoViewPage<RenderModel> which inherits from
Umbraco.Web.Mvc.UmbracoViewPage<TModel> which finally inherits from the MVC base class that you were trying to use.
If you were to try using this:
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent> it would work, this is because:
The property Umbraco exists on that base class, so you can do things like @Umbraco.Field
The Model for that base class is IPublishedContent which will work with Articulate models because all Articulate models are of type IPublishedContent
It will work with normal Umbraco pages because they are all compatible and use the model IPublishedContent
Other page types together with the Articuate Blog
I have set up an Articulate Blog. Everything works just fine, seems to be a really well-built plugin :-)
The blog is in the root of the domain, and I would like to add a few menu items that are not part of the blog (like "About" and "Contact"). I have made a document type and a template for the "About"-page in the Umbraco backoffice, but I get this error:
"The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'Articulate.Models.IMasterModel'"
My template looks like this:
@using Articulate
@using Umbraco.Core;
@model Articulate.Models.IMasterModel
@{
Layout = "~/App_Plugins/Articulate/Themes/Shazwazza/Views/Master.cshtml";
}
I also tried to create the view in the Articulate theme-folder, but how can I select it from the backoffice?
Hi, Yes lots of people ask this question (or essentially have the same underlying problem). This is because of how MVC and it's views work.
Lots of details here: https://our.umbraco.org/projects/starter-kits/articulate/discussions/54733-Articulate-integration-in-existing-site
It sounds like you've copied and pasted markup in to your new Umbraco template instead of keeping the defaults. By default and Umbraco template will have:
You have:
Which (as posted in the above article) is syntactic sugar for:
The problem with your custom page is that Umbraco passes in a model to your view of type
RenderModel
but your view is expecting a model of typeIMasterModel
, so that is why you are getting that exception.So the first thing you can do is change
@model Articulate.Models.IMasterModel
back to what Umbraco's default is:@inherits Umbraco.Web.Mvc.UmbracoViewPage
However you will still have an issue because your layout page that you are using
Layout = "~/App_Plugins/Articulate/Themes/Shazwazza/Views/Master.cshtml";
is also going to expect that it be given a model of typeArticulate.Models.IMasterModel
. The post referenced above also has information about that too and this all depends on if you need a layout page with a strongly typed model or not. There's no right answer to all of this, it really depends on how you structure your templates.Hi all
How can I add an other webpage "about" with text and image content? I'm running everytime in the same issue as above...
thaks for help.
BR Manuel
Did you read the link I posted above? There's lots of information there
Yes I tried a few things but nothing helped.... I tried dynamic, IMasterModel and so on. What do you recommend to implementing a normal page?
if I try some solutions I have the follwing issue:
@inherits Umbraco.Web.Mvc.UmbracoViewPage
or @model dynamic
@{
var articulateMasterModel = Model as IMasterModel;
if (articulateMasterModel == null)
{ }
}
I got everytime a null reference exception!
@articulateMasterModel.Name - @articulateMasterModel.BlogTitle
Ok, I'll try to explain this again. This is how MVC works, this is not an Articulate or Umbraco thing, it's just how ASP.Net MVC works.
Let say I have this, for example:
BlogPage.cshtml might be of model type:
IMasterModel
. Now i can render anything in this view based on the model values.CustomPage.cshtml might be of model type:
MyCoolModel
, Now i can render anything in this view based on the model values.Both of these templates use the same layout: _MasterLayout.cshtml. The layout cannot be 2 different types of models at the same time, that is not possible. Therefore the _MasterLayout.cshtml would have to
dynamic
Taking this into account it should be pretty clear why this doesn't work on your master layout page:
It will of course be null when rendering a non-articulate umbraco page because the model will be
IPublishedContent
.Next, you need to know what things like
@inherits Umbraco.Web.Mvc.UmbracoViewPage
actually mean. I've mentioned this a few times in the link i posted earlier but will re-iterate again:@inherits Umbraco.Web.Mvc.UmbracoViewPage
-->
UmbracoViewPage<IPublishedContent>
--->
System.Web.Mvc.WebViewPage<IPublishedContent>
----> The model is
IPublishedContent
It is also important to know that in Articulate that all instances of
IMasterModel
are alsoIPublishedContent
Therefore, your master view that is shared with both articulate and regular Umbraco pages can have a model of
IPublishedContent
and you can use this model like you would normally in Umbraco.I kind of understand what you are saying but still having issues.
My master page using this: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
This is required for things like: @Umbraco.Field("...")
Your last sentence:
Seems to suggest that I should be able to use this model for a master page that is shared with both Articulate and my site's master page:
@model IPublishedContent
.. But this doesn't work. :(
If I do it like this:
I get this error:
The type or namespace name 'Field' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
I tried every combination of different models that Shannon mentioned, but I was only able to get this to work by changing my Master model to use this:
Nothing else worked. Thanks for helping me through this.
@Jeff, you are getting errors because you are using the wrong base classes.
This base class:
@inherits System.Web.Mvc.WebViewPage
is the MVC base class for views, this means it does not contain all of the Umbraco properties like @Umbraco @UmbracoContext, etc... This also means that it cannot process things like @Umbraco.Field because the property
Umbraco
does not exist on the classSystem.Web.Mvc.WebViewPage<T>
. Does that make sense ?The base class that we use by default for views is:
Umbraco.Web.Mvc.UmbracoTemplatePage
which inherits fromUmbraco.Web.Mvc.UmbracoViewPage<RenderModel>
which inherits fromUmbraco.Web.Mvc.UmbracoViewPage<TModel>
which finally inherits from the MVC base class that you were trying to use.If you were to try using this:
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
it would work, this is because:Umbraco
exists on that base class, so you can do things like @Umbraco.FieldIPublishedContent
which will work with Articulate models because all Articulate models are of typeIPublishedContent
IPublishedContent
is working on a reply...