Copied to clipboard

Flag this post as spam?

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


  • LoisLane 6 posts 56 karma points
    Mar 19, 2015 @ 13:35
    LoisLane
    0

    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?

  • Shannon Deminick 1524 posts 5270 karma points MVP 2x
    Mar 19, 2015 @ 22:22
    Shannon Deminick
    0

    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:

     @inherits Umbraco.Web.Mvc.UmbracoViewPage
    

    You have:

     @model Articulate.Models.IMasterModel
    

    Which (as posted in the above article) is syntactic sugar for:

     @inherits System.Web.Mvc.WebViewPage<Articulate.Models.IMasterModel>
    

    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.

  • lele 102 posts 429 karma points
    May 23, 2015 @ 14:48
    lele
    0

    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 

  • Shannon Deminick 1524 posts 5270 karma points MVP 2x
    May 26, 2015 @ 01:28
    Shannon Deminick
    0

    Did you read the link I posted above? There's lots of information there

  • lele 102 posts 429 karma points
    May 26, 2015 @ 08:47
    lele
    0

    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?

  • lele 102 posts 429 karma points
    May 27, 2015 @ 21:37
    lele
    0

    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
  • Shannon Deminick 1524 posts 5270 karma points MVP 2x
    Jun 03, 2015 @ 14:05
    Shannon Deminick
    0

    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:

    @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 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.

  • Jeff Kershner 8 posts 38 karma points
    Jul 30, 2015 @ 21:10
    Jeff Kershner
    0

    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:

    @model IPublishedContent

    .. But this doesn't work. :(

  • Jeff Kershner 8 posts 38 karma points
    Jul 30, 2015 @ 21:13
    Jeff Kershner
    0

    If I do it like this:

    @inherits System.Web.Mvc.WebViewPage<IPublishedContent>
    

    I get this error:

    The type or namespace name 'Field' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)

  • Jeff Kershner 8 posts 38 karma points
    Jul 31, 2015 @ 03:37
    Jeff Kershner
    0

    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:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
    

    Nothing else worked. Thanks for helping me through this.

  • Shannon Deminick 1524 posts 5270 karma points MVP 2x
    Aug 11, 2015 @ 08:47
    Shannon Deminick
    0

    @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
Please Sign in or register to post replies

Write your reply to:

Draft