Copied to clipboard

Flag this post as spam?

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


  • Bert Hoorne 15 posts 55 karma points
    Jun 28, 2015 @ 06:25
    Bert Hoorne
    0

    Item.GetValue("header") Value cannot be null.

    Hi,

    I created a custom header, with only 1 property, a single textstring. Every time I try to show the values, I get the error: : Value cannot be null.

    HTML:

    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    @foreach (var item in Model.Items)
    {
        <div class="row">
            <div class="col-sm-6 col-sm-offset-3">
                <h2 class="module-title font-alt">@item.GetValue("Header")</h2>
            </div>
        </div>
    }
    

    The stacktrace:

       at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
       at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
       at System.Int32.Parse(String s)
       at Lecoati.LeBlender.Extension.Helper.GetTargetContentType()
       at Lecoati.LeBlender.Extension.Models.LeBlenderPropertyModel.GetValue[T]()
       at Lecoati.LeBlender.Extension.Models.LeBlenderValue.GetValue[T](String propertyAlias)
       at Lecoati.LeBlender.Extension.Models.LeBlenderValue.GetValue(String propertyAlias)
       at ASP._Page_views_partials_grid_editors_ModuleTitel_cshtml.Execute() in c:\Projects\keystroke\Rovasac website\Web solution\Source\Rovasac\Views\Partials\Grid\Editors\ModuleTitel.cshtml:line 6
       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)
    

    The backend enter image description here

    The wierd thing is, it is only on some document types, not on all of them.

    Any ideas?

    Thanks :)

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Jun 29, 2015 @ 22:07
    Alex Skrypnyk
    0

    Hi Bert,

    Can you use 'HasValue()' method for checking value before using it ?

    Thanks

  • Bert Hoorne 15 posts 55 karma points
    Jul 01, 2015 @ 18:04
    Bert Hoorne
    0

    Hi Alex,

    My object does not have a property HasValue, enter image description here

    Is it correct that I inherit from :

    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    

    Thanks!

  • Antoine 176 posts 1494 karma points
    Jul 01, 2015 @ 18:28
    Antoine
    0

    Hi Bert,

    I think that it because the alias of your property is header and not Header, the alias is camel case.

  • Bert Hoorne 15 posts 55 karma points
    Jul 01, 2015 @ 19:15
    Bert Hoorne
    0

    Hi, I tried this too, but still same issue :(

  • Antoine 176 posts 1494 karma points
    Jul 02, 2015 @ 17:33
    Antoine
    0

    Hi Bert,

    I tried it with exactly the same values but it works fine for me :/

    Have you got any more info about your issue, some error within the console? you have this error in front or back?

  • Bert Hoorne 15 posts 55 karma points
    Jul 14, 2015 @ 19:54
    Bert Hoorne
    0

    Hi,

    I downloaded the source code and found that this is null:

    string.IsNullOrEmpty(HttpContext.Current.Request["id"]
    

    located in

         internal static PublishedContentType GetTargetContentType()
    

    The possible reason is because I am using a custom controller and the Id is not set.

    In my controller I added the ID to HttpContext.Current.Items collection and wrote some extra code in Leblender Extension to retreive this id

     else if (!string.IsNullOrEmpty(HttpContext.Current.Request["id"]))
            {
                int contenId = int.Parse(HttpContext.Current.Request["id"]);
                return (PublishedContentType)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
                    "LeBlender_GetTargetContentType_" + contenId,
                    () =>
                    {
                        var services = ApplicationContext.Current.Services;
                        var contentType = PublishedContentType.Get(PublishedItemType.Content, services.ContentService.GetById(contenId).ContentType.Alias);
                        return contentType;
                    });
            }
            else
            {
                int contenId = int.Parse(HttpContext.Current.Items["id"].ToString());
                return (PublishedContentType)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
                    "LeBlender_GetTargetContentType_" + contenId,
                    () =>
                    {
                        var services = ApplicationContext.Current.Services;
                        var contentType = PublishedContentType.Get(PublishedItemType.Content, services.ContentService.GetById(contenId).ContentType.Alias);
                        return contentType;
                    });
            }
    

    Does anyone knows why this ID is null? And who sets it?

    Thanks :)

    (it works with my changes for now)

  • 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