Copied to clipboard

Flag this post as spam?

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


  • Emmali Montgomery 4 posts 74 karma points
    Aug 11, 2016 @ 15:08
    Emmali Montgomery
    0

    Rendering a Partial inside a Macro

    Hi,

    I have a macro that is being used to loop through a media type full of carousel images. That part, as well as the if statement defining which image I really want, is working beautifully as a banner. My problem is that the banner is supposed to have breadcrumbs over top that allow the user to go back a page in the directory. The code is a little complicated, so it's in a partial in an attempt to make things cleaner. The partial won't render. Right now, I have it commented out so that I can work with the macro, but as soon as I uncomment it the macro breaks. This is how I'm trying to render the partial: @Html.Partial("_BreadCrumbs")

    I've tried researching this, but no matter what keywords I use my searches bring up how to render a macro inside a partial... which is the complete opposite of what I want. Also, the code I'm using to render the partial is the same code I would be using in a Template, which works.

  • Emmali Montgomery 4 posts 74 karma points
    Aug 11, 2016 @ 19:28
    Emmali Montgomery
    0

    This article helped me understand the problem more, but the solutions posed here haven't solved anything for me... The error that I keep getting is: Error loading Partial View script (file: ~/Views/MacroPartials\_BannerPicker.cshtml)

  • Mark 119 posts 252 karma points
    Aug 12, 2016 @ 08:36
    Mark
    0

    Hi Emmali,

    your sample above looks slightly wrong, you have mixed slashes. Rendering a partial inside a macro should be as simple as:

    @Html.Partial("~/views/partials/_BannerPicker.cshtml")
    

    Hopefully this helps?

    Mark

  • Emmali Montgomery 4 posts 74 karma points
    Aug 12, 2016 @ 12:15
    Emmali Montgomery
    0

    Hi Mark,

    I've since fixed the mixed slash issue, but when I try to force the directory like that it still doesn't work... Is the directory case-sensitive? Also, what exactly does the little tilde do? The directories actually look like below... I just omitted the one layer because I didn't think it was important.

    • Views
      • MacroPartials
        • SiteName
          • BannerPicker.cshtml (the macro I'm working with)
      • Partials
        • SiteName
          • BreadCrumbs.cshtml (the partial I'm trying to display inside it)
      • Template1
      • Template 2

    My code looks like this:

    @Html.Partial("~/views/partials/sitename/_BreadCrumbs.cshtml")
    

    If I comment out the above line of code the macro works just fine, so I know it's an issue connecting the two.

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Aug 14, 2016 @ 10:37
    Alex Skrypnyk
    0

    Hi Emmali,

    Little tilde should move start of your traversing to root folder of web application.

    Directory names are not case-sensitive.

    I think you can try to render your partial like:

    @Html.Partial("sitename/_BreadCrumbs.cshtml")
    

    Because Partial is looking int Partials folder by default.

    Thanks,

    Alex

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies