Imagine being paid to improve your favorite CMS!

It could be you! Umbraco HQ are hiring and are looking for both talents and senior developers. Wonderful workplace, friendly colleagues and competitive salary.

Copied to clipboard

Flag this post as spam?

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


  • Nico 2 posts 93 karma points
    Nov 17, 2015 @ 10:07
    Nico
    0

    Web api - GetGridHtml not working

    LeBlender is crashing when GetGridHtml is called in WebAPI.

    Example:

       int nodeId = 1300;
        UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);
        IPublishedContent samplecontent= helper.TypedContent(nodeId);
        samplecontent.GetGridHtml("grid");
    

    The crash is because of HttpContext.Current.Request["id"] does not exist in LeBlenderHelper.cs. (Line 234)

    When for example

    item.GetValue<string>("text")
    

    is called the code crashed and no value is returned.

    I found a simple workaround, but don't know if this is the right solution.

    Changed the code in LeBlenderHelper.cs. (Line 222 till 245)

     internal static PublishedContentType GetTargetContentType()
            {
                if (UmbracoContext.Current.IsFrontEndUmbracoRequest)
                {
                    return GetUmbracoHelper().AssignedContentItem.ContentType;
                }
                else if (!string.IsNullOrEmpty(HttpContext.Current.Request["doctype"]))
                {
                    return PublishedContentType.Get(PublishedItemType.Content, HttpContext.Current.Request["doctype"]);
                }
                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;
                        });
                }
                return null;
            }
    

    Can this be fixed in next version?

Please Sign in or register to post replies

Write your reply to:

Draft