Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    Sep 25, 2015 @ 13:45
    Martin
    0

    Check if ID is still valid in content picker

    Hi,

    Im trying to check if a page node existing when using the content picker data type. So if a page is deleted, then the link is not outputted.

    Any help would be grateful.

    Martin

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    
    <div>
        @Umbraco.Field(Model, "callToActionContent")
    
        @if(Model.HasValue("callToActionButtonLink")){
            var button = Model.GetPropertyValue<IPublishedContent>("callToActionButtonLink");
            <div class="btn">
                <a href="@button.Url">Contact &raquo;</a>
            </div>  
        }
    </div>
    
  • Kasper Holm 47 posts 180 karma points
    Sep 25, 2015 @ 14:28
    Kasper Holm
    1

    Hi Martin i think you should do something like this

     @inherits Umbraco.Web.Mvc.UmbracoViewPage
    
    <div>
    @{
          var button = Model.GetPropertyValue<IPublishedContent("callToActionButtonLink");
     }
    
      @if(button != null){
            <div class="btn">
                <a href="@button.Url">Contact &raquo;</a>
            </div>  
        }
    </div>
    
  • 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