Copied to clipboard

Flag this post as spam?

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


  • Nicolai 48 posts 201 karma points
    Mar 20, 2015 @ 12:58
    Nicolai
    0

    Error loading Partial View script?

    Im trying to convert a Scripting File into a Partial View Macro File, and I cant really figure out why its not loading. Can anyone see what im doing wrong? I've added the code for both the scripting file and the partial view macro.

    Scripting File:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        if (@Model.HasProperty("homepageArticleTags"))
        {
            var tagsList = Model.homepageArticleTags;
            if (tagsList != null)
            {
        <h2><span>Kategorier:</span></h2>
        <ul>
            @foreach (var tag in tagsList)
            {
                <li class="magazineTags">
                    <a href="/SearchOverview.aspx?tag=@tag">@tag</a>
                </li>
            }
        </ul>
            }
        }
    }

     

    Partial View Macro File:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{
    if (@CurrentPage.HasProperty("homepageArticleTags")) 
    { var tagsList = CurrentPage.homepageArticleTags; }
    }
    @if (tagsList != null)
    {
        <h2><span>Kategorier:</span></h2>
        <ul>
            @foreach (var tag in tagsList)
            {
                <li class="magazineTags">
                    <a href="/SearchOverview.aspx?tag=@tag">@tag</a>
                </li>
            }
        </ul>
    }
    }
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 20, 2015 @ 13:06
    Dennis Aaen
    0

    Hi Nicolai,

    What if you do something like this would it work?

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
     
     @{
        if (CurrentPage.HasProperty("homepageArticleTags")) {
                var tagsList = CurrentPage.homepageArticleTags;
            }
       }
       if (tagsList != null){
               <h2><span>Kategorier:</span></h2>
              <ul>
                 @foreach (var tag in tagsList)
                    <li class="magazineTags">
                        <a href="/SearchOverview.aspx?tag=@tag">@tag</a>
                     </li>
                }
              </ul>
        }
    }

    Hope this helps,

    /Dennis

  • Nicolai 48 posts 201 karma points
    Mar 20, 2015 @ 13:34
    Nicolai
    0

    It still doesnt load. Im getting the fallowing error at where im trying to display this macro:

    "Error loading Partial View script (file: ~/Views/MacroPartials/AllNodeArticleTags.cshtml)"

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 20, 2015 @ 14:08
    Dennis Aaen
    100

    Hi Nicolai,

    I just have a second look at your code, and I think that this updated version would work for you.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
     
     @{
        if (CurrentPage.HasProperty("homepageArticleTags")) {
             var tagsList = CurrentPage.homepageArticleTags;
            if(tagsList != null){
               <h2><span>Kategorier:</span></h2>
              <ul>
                   @foreach (var tag in tagsList) {
                    <li class="magazineTags">
                        <a href="/SearchOverview.aspx?tag=@tag">@tag</a>
                     </li>
                }
              </ul>

             }
           }
         
    }

    Hope this helps,

    /Dennis

  • Nicolai 48 posts 201 karma points
    Mar 20, 2015 @ 14:20
    Nicolai
    1

    Nevermind, I got it to work.

    I forgot that tagsList is from the datatype tags and they are Comma Separated Strings. I just added tagsList.Split(',')

    Thanks alot for the help, can you explain why it didnt work in the first place?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 20, 2015 @ 14:26
    Dennis Aaen
    0

    Hi Nicolai,

    What type of field did you use in the backoffice to add and store the tags, a text string the property editor that is named tags?

    Looking forward to hear from you :-)

    /Dennis

  • Nicolai 48 posts 201 karma points
    Mar 20, 2015 @ 14:38
    Nicolai
    0
Please Sign in or register to post replies

Write your reply to:

Draft