Copied to clipboard

Flag this post as spam?

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


  • JJ 41 posts 83 karma points
    Jan 29, 2014 @ 10:56
    JJ
    0

    Media properties which are null

    Hi all

    I have added a new property to the Image media type called Link which is a Content Picker. It is optional.

    I'm using the contents of a media folder to populate an image slider, and therefore need the link property for the hyperlink of each slider (or not if the user decides they dont want a link for that particular image.)

    I'm using a simple partial (snippet below), but it's throwing an error if an image has no link property set.

    This is version 7.0.2. How do I handle null properties?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    <ul class="example-orbit" data-orbit>
    
        @foreach (var item in @Umbraco.Media(1148).Children)
        {
        <li>
            @{
                var link = "#";
            }
            @if (null != @item.link)  // get error here
            {
                link = @Umbraco.Content(item.link).Url;
            }
            <a data-reveal-id="myModal" href="@link">
                <img src="@item.Url" alt="@item.Name" />
            </a>
        </li>
    
        }
    </ul>

     

    Exception:

    An exception of type 'System.ArgumentNullException' occurred in Umbraco.Core.dll but was not handled in user code
    
    Additional information: Value cannot be null
    
       at Umbraco.Core.Models.PublishedContent.PublishedPropertyBase..ctor(PublishedPropertyType propertyType)
       at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty..ctor(PublishedPropertyType propertyType, Boolean isPreviewing)
       at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty..ctor(PublishedPropertyType propertyType, Boolean isPreviewing, String propertyData)
       at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.DictionaryPublishedContent..ctor(IDictionary`2 valueDictionary, Func`2 getParent, Func`2 getChildren, Func`3 getProperty, Boolean fromExamine)
       at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.ConvertFromXPathNavigator(XPathNavigator xpath)
       at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.GetProperty(DictionaryPublishedContent dd, String alias)
       at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.DictionaryPublishedContent.GetProperty(String alias)
       at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache.DictionaryPublishedContent.GetProperty(String alias, Boolean recurse)
       at Umbraco.Core.Models.PublishedContent.PublishedContentWrapped.GetProperty(String alias, Boolean recurse)
       at Umbraco.Web.PublishedContentExtensions.GetPropertyValue(IPublishedContent content, String alias, Boolean recurse)
       at Umbraco.Web.Models.DynamicPublishedContent.TryGetUserProperty(GetMemberBinder binder)
       at Umbraco.Web.Models.DynamicPublishedContent.<>c__DisplayClass9.<TryGetMember>b__6(Func`2 m)
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
       at Umbraco.Web.Models.DynamicPublishedContent.TryGetMember(GetMemberBinder binder, Object& result)
       at CallSite.Target(Closure , CallSite , Object )
       at ASP._Page_Views_Partials_Rotator_cshtml.Execute() in d:\Work\TFS\The Avenue Website\Stardust\CMS\Views\Partials\Rotator.cshtml:line 10
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
       at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
       at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName)
       at ASP._Page_Views_Homepage_cshtml.Execute() in d:\Work\TFS\The Avenue Website\Stardust\CMS\Views\Homepage.cshtml:line 9
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)

    Thanks

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Jan 29, 2014 @ 22:07
    Sebastiaan Janssen
    0

    It's a known issue in v7, we're getting a 7.0.3 out very soon that will solve the problem. Sorry about that! Make sure to keep an eye on our blog to learn when it's available!

  • JJ 41 posts 83 karma points
    Jan 30, 2014 @ 10:37
    JJ
    0

    Ah, ok. Any idea on timeframe? I've got to launch this site soon.

     

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Jan 30, 2014 @ 11:13
    Sebastiaan Janssen
    100

    Nope. Soon. Nightlies are available now with media fixes if you want to try it out, should be very stable as it's just a few little fixes on top of the 7.0.2 release: http://nightly.umbraco.org/umbraco%207.0.3/ (only dll changes, so just overwrite your bin folder).

  • JJ 41 posts 83 karma points
    Jan 30, 2014 @ 11:15
    JJ
    0

    OK, thanks.

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Jan 30, 2014 @ 17:26
    Sebastiaan Janssen
    0

    As I said, just copy the bin folder from the nightly and overwrite the files in your current bin folder.

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Feb 03, 2014 @ 16:28
    Sebastiaan Janssen
    0

    FYI: 7.0.3 was released this morning, if you're on 7.0.1 or 7.0.2 it's a super easy upgrade (basically overwrite the /bin /install /umbraco and /umbraco_client folders, step through the installer and you're done).

    http://umbraco.com/follow-us/blog-archive/2014/2/3/released-umbraco-703.aspx

Please Sign in or register to post replies

Write your reply to:

Draft