Copied to clipboard

Flag this post as spam?

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


  • Patrick Davis 3 posts 73 karma points
    Aug 27, 2019 @ 11:34
    Patrick Davis
    0

    Trouble with MultiUrlPicker

    Hi,

    I am having some trouble using the core URL picker. I followed the documentation exactly but my model is always null.

    Here's the relevant cshtml from my _Footer partial, which is rendered by a site layout controller in my master template.

    _Footer.cshtml

    @inherits  UmbracoViewPage
    
    @using Umbraco.Web.Models
    @{
    IEnumerable<Link> footerLinks = Model.Value<IEnumerable<Link>> 
    ("footerLinks", fallback: Fallback.ToAncestors);
    }
    <footer id="footer">
    <div class="inner">
        <div class="content">
            <section>
                <h4 style="text-align:center">Networks</h4>
                <hr />
    
                @{
    
              if (footerLinks.Any())
            {
                <ul class="plain">
                    @foreach (var link in footerLinks)
                    {
                        <li><a href="@link.Url" 
              target="@link.Target">@link.Name</a></li>
                    }
                </ul>
            }
        }
            </section>
    

    Controller

      public ActionResult RenderFooter()
        {
            return PartialView(PARTIAL_VIEW_FOLDER_PATH + "_Footer.cshtml");
        }
    

    Master

    <!-- Footer -->
    @{ Html.RenderAction("RenderFooter", "SiteLayout");}
    

    Error

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of 
    the current web request. Please review the stack trace for more 
    information about the error and where it originated in the code. 
    
    Exception Details: System.NullReferenceException: Object reference not 
    set to an instance of an object.
    
    Source Error: 
    
    
     Line 3:  @using Umbraco.Web.Models
     Line 4:  @{
     **Line 5:  IEnumerable<Link> footerLinks = Model.Value<IEnumerable<Link>> 
      ("footerLinks", 
     fallback: Fallback.ToAncestors);**
     Line 6:  }
     Line 7:  <footer id="footer">
    

    CMS doc type

    Any help would be really appreciated.

  • Shaishav Karnani from digitallymedia.com 349 posts 1631 karma points
    Aug 27, 2019 @ 13:09
    Shaishav Karnani from digitallymedia.com
    0

    Hi Patrick,

    Is your footerLinks on the same page that you are trying to access. I think it could be one level up and so you need to add below code.

    Model.Value<IEnumerable<Link>>("footerLinks", fallback: Fallback.ToAncestors);
    
  • Patrick Davis 3 posts 73 karma points
    Aug 27, 2019 @ 14:23
    Patrick Davis
    0

    Hi Shaishav,

    Unfortunately, this was not the solution. I really appreciate the input though. The footer is for global use, not page by page basis. If it helps, I'll attach a picture of my structure. Folder Structure

  • Patrick Davis 3 posts 73 karma points
    Aug 27, 2019 @ 14:54
    Patrick Davis
    0

    Fix:

    The guide doesn't account for different setups, what has confused me is the use of a model when this isn't a custom model. In fact, I was able to access it with this instead:

    @{
       IEnumerable<Link> footerLinks = Umbraco.AssignedContentItem.Value<IEnumerable<Link>>("footerLinks", fallback: Fallback.ToAncestors); 
    }
    
  • 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