Copied to clipboard

Flag this post as spam?

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


  • Gísli Freyr Svavarsson 43 posts 126 karma points
    Jan 18, 2017 @ 10:26
    Gísli Freyr Svavarsson
    0

    Rendering partial view in macro

    Hi kids.

    Is it possible to render a partial view in a macro? When I try

    @Html.Partial("_PARTIAL-ALIAS")
    

    I get this error "Cannot bind source type Umbraco.Web.Models.PartialViewMacroModel to model type Umbraco.Web.Models.RenderModel."

    @Umbraco.Field("_search-form")
    

    This doesn't render the content.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jan 18, 2017 @ 10:55
    Dennis Adolfi
    100

    Hi Gísli.

    The way you've written in you first code is correct, by writing Html.Partial(".."). The problem however is that if you are inside a macro partial view (which im suspecting), then that view is inheriting from PartialViewMacroModel and the partial view that you trying to include with a partial has a model of type RenderModel, usually because partial views created from the backoffice have this as the first line of code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    How does your partial look? Can you paste in your code from the search-form partial? Do you need that partial to inherit from UmbracoTemplatePage? If not then remove that line. If yes, we can have a look at your code and see how to fix this.

    Take care!

  • Gísli Freyr Svavarsson 43 posts 126 karma points
    Jan 18, 2017 @ 11:28
    Gísli Freyr Svavarsson
    1

    Thank you Dennis. I removed the @inherits Umbraco.Web.Mvc.UmbracoTemplatePage and that did the trick.

    mvh

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jan 18, 2017 @ 11:36
    Dennis Adolfi
    0

    Awesome! Happy to be able to help! :)

    Take care and have a great day!

  • Wilson Almonte 5 posts 75 karma points
    Mar 19, 2020 @ 20:09
    Wilson Almonte
    0

    Also you can use Html.RenderPartial, and with this you don't need to remove @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

Please Sign in or register to post replies

Write your reply to:

Draft