Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 326 posts 978 karma points MVP c-trib
    Jun 20, 2015 @ 13:20
    Owain Williams
    0

    Umbraco Site Navigation Macro within Template

    Hi, I have my main site which has a macro which dynamically created my site nav. I wanted to use this within Articulate as well but having some problems getting it to work.

    My macro sites in ~/Views/MacroPartials/siteNav.cshtml but if I try to load the partial with

    @HTML.Partial("~/Views/MacroPartials/siteNav.cshtml") - Visual Studio throws an error -

    An exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code
    
    Additional information: The model item passed into the dictionary is of type 'Articulate.Models.ListModel', but this dictionary requires a model item of type 'Umbraco.Web.Models.PartialViewMacroModel'. 
    

    How do I fix this? Thanks.

  • Casper Andersen 126 posts 506 karma points
    Jun 22, 2015 @ 08:12
    Casper Andersen
    0

    I am not great on macros, but my understanding is that you create a macro and then create the macro partial view so should you not be asking for the macro instead of its partial view ?

  • Shannon Deminick 1446 posts 4869 karma points hq
    Jun 22, 2015 @ 09:56
    Shannon Deminick
    101

    You are trying to render a Macro as a Partial View. These are 2 different things. A Partial View, is an MVC partial view. A Macro uses a Partial View but can have specific parameters passed to the view.

    If you are just trying to render an MVC Partial View, you don't need to create a macro, you just use MVC Partial Views the way that they were designed. Macro's generally aren't necessary unless you are embedding them in a rich text editor, or your editors need to pass in specific macro parameters.

    You are getting this exception because your view is expecting a model of PartialViewMacroModel ... which is used by partial view macros, but the model being used to render your page is ListModel (which is of type IPublishedContent).

    You can read more about macros here: https://our.umbraco.org/Documentation/Getting-Started/Design/Templates/Macros/

  • Owain Williams 326 posts 978 karma points MVP c-trib
    Jun 22, 2015 @ 11:58
    Owain Williams
    0

    Thanks! I just followed a tutorial which showed me to put the code in to a macro. I've moved it out and the code still works in the partial. Will look at pulling that over to the template but can't see why it won't work now.

    Thanks for your help both! Another step closer to getting my site launched!

Please Sign in or register to post replies

Write your reply to:

Draft