Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recursive:true throws Exception #44

Closed
tommyTanaka opened this issue Mar 19, 2016 · 14 comments
Closed

recursive:true throws Exception #44

tommyTanaka opened this issue Mar 19, 2016 · 14 comments
Milestone

Comments

@tommyTanaka
Copy link

Hi,

this code throws the following exception. If there is a value in the property, it works but without, I got the error.

if(Model.Content.HasVortoValue("keywords", recursive: true))
{
    keywords = Model.Content.GetVortoValue("keywords", recursive: true).ToString();
}

Exception:
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.DoInnerGetVortoValue[T](IPublishedContent content, String propertyAlias, String cultureName, Boolean recursive, T defaultValue)
bei Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.GetVortoValue[T](IPublishedContent content, String propertyAlias, String cultureName, Boolean recursive, T defaultValue, String fallbackCultureName)
bei Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.GetVortoValue(IPublishedContent content, String propertyAlias, String cultureName, Boolean recursive, Object defaultValue, String fallbackCultureName)
bei ASP._Page_Views_MacroPartials_Metatags_cshtml.Execute()

@mattbrailsford
Copy link
Collaborator

What version of vorto are you using? I believe this should have been fixed in 1.5.1

@tommyTanaka
Copy link
Author

Ok, Version 1.4 was installed. I updated to 1.5.1 and now, my Grid-Renderer throws an error:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: string enthält keine Definition für sections. bei CallSite.Target(Closure , CallSite , Object ) bei ASP._Page_Views_Partials_Grid_bootstrap3_cshtml.Execute() in c:\inetpub\wwwroot\umbHbiG\Views\Partials\Grid\Bootstrap3.cshtml:Zeile 9. bei System.Web.WebPages.WebPageBase.ExecutePageHierarchy() bei System.Web.Mvc.WebViewPage.ExecutePageHierarchy() bei System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) bei Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) bei System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) bei ASP._Page_Views_MacroPartials_RenderInhaltsseite_cshtml.Execute() in c:\inetpub\wwwroot\umbHbiG\Views\MacroPartials\RenderInhaltsseite.cshtml:Zeile 8.

@tommyTanaka
Copy link
Author

With Version : 1.5.0-alpha-000022, it works.

@tommyTanaka
Copy link
Author

Sorry, wir 1.5.0.-alpha 26. I'm running Umbraco 7.4.1

@tommyTanaka
Copy link
Author

But here I still get the error:
ystem.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.DoInnerGetVortoValue[T](IPublishedContent content, String propertyAlias, String cultureName, Boolean recursive, T defaultValue)
bei Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.GetVortoValue[T](IPublishedContent content, String propertyAlias, String cultureName, Boolean recursive, T defaultValue, String fallbackCultureName)
bei Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.GetVortoValue(IPublishedContent content, String propertyAlias, String cultureName, Boolean recursive, Object defaultValue, String fallbackCultureName)
bei ASP._Page_Views_MacroPartials_Metatags_cshtml.Execute() in c:\inetpub\wwwroot\umbHbiG\Views\MacroPartials\Metatags.cshtml:Zeile 15.

Happy easter, by the way and thanks for listening. :)

@mattbrailsford
Copy link
Collaborator

mattbrailsford commented Mar 27, 2016 via email

@tommyTanaka
Copy link
Author

Fixed the problem from this post, but I get the grid-render error again.

@mattbrailsford
Copy link
Collaborator

Can you explain your setup a bit further? How is the grid relevant to the vorto property?

@mattbrailsford
Copy link
Collaborator

Also, what is happening in RenderInhaltsseite.cshtml at line 8?

@tommyTanaka
Copy link
Author

It renders a Vorto Datatype of grid in a PartialView Macro with:

@{      
    try
    {
    if(Model.Content.HasVortoValue("Grid")){
        @Html.Partial("Grid/bootstrap3",Model.Content.GetVortoValue("Grid"))
    }
    }
    catch(Exception e)
    {
        <p>@e.ToString()</p>
    }
}

@mattbrailsford
Copy link
Collaborator

And what's the code in Bootstrap3.cshtml?

@tommyTanaka
Copy link
Author

I setup a normal Grid and connected it to the vorto datatype.
In Version 1.5.0 Alpha, everything works.

This is the common umbraco code:

@inherits UmbracoViewPage<dynamic>
@using Umbraco.Web.Templates
@using Newtonsoft.Json.Linq

@* 
    Razor helpers located at the bottom of this file
*@

@if (Model != null && Model.sections != null)
{
    var oneColumn = ((System.Collections.ICollection)Model.sections).Count == 1;

    <div class="umb-grid">
        @if (oneColumn)
        {
            foreach (var section in Model.sections) {
                <div class="grid-section">
                    @foreach (var row in section.rows) {
                        @renderRow(row, true);
                    }
                </div>
            }   
        }else { 
            <div class="container">
                <div class="row clearfix">
                    @foreach (var s in Model.sections) {
                        <div class="grid-section">
                            <div class="col-md-@s.grid column">
                                @foreach (var row in s.rows) {
                                    @renderRow(row, false);
                                }
                            </div>
                        </div>
                    }
                </div>
            </div>   
        }
    </div>
}

@helper renderRow(dynamic row, bool singleColumn){
    <div @RenderElementAttributes(row)>
        @Umbraco.If(singleColumn, "<div class='container'>")
        <div class="row clearfix">
            @foreach ( var area in row.areas ) {
            <div class="col-md-@area.grid column">
                <div @RenderElementAttributes(area)>
                    @foreach (var control in area.controls) {
                        if (control !=null && control.editor != null && control.editor.view != null ) {
                            <text>@Html.Partial("grid/editors/base", (object)control)</text>
                        }
                    }
                </div>
            </div>}
        </div>
        @Umbraco.If(singleColumn, "</div>")
    </div>
}

@functions {
    public static MvcHtmlString RenderElementAttributes(dynamic contentItem)
    {
        var attrs = new List<string>();
        JObject cfg = contentItem.config;

        if(cfg != null)
            foreach (JProperty property in cfg.Properties()) {
                attrs.Add(property.Name + "=\"" + property.Value.ToString() + "\"");
            }

        JObject style = contentItem.styles;

        if (style != null) { 
        var cssVals = new List<string>();
        foreach (JProperty property in style.Properties())
            cssVals.Add(property.Name + ":" + property.Value.ToString() + ";");

        if (cssVals.Any())
            attrs.Add("style=\"" + string.Join(" ", cssVals) + "\"");
        }

        return new MvcHtmlString(string.Join(" ", attrs));
    }
}

mattbrailsford added a commit that referenced this issue Mar 27, 2016
…ck to do with issue #19 in which we made ConvertSourceToObject get called first. At the time, I had forgotten why I had them in the order I did, but I remembered the reason now and so added a comment also so we don't forget. ConvertDataToSource MUST occur before ConvertSourceToObject.
@mattbrailsford
Copy link
Collaborator

Ok, I know what the problem is now. We switched some code around when converting a values type to the target type, which seems to break this. Have switched it back and added a comment to ensure it doesn't get moved again in future. Try this build: https://ci.appveyor.com/project/mattbrailsford/umbraco-vorto/build/1.5.2.45/artifacts

@tommyTanaka
Copy link
Author

Best easter egg of the day. This fixed the problem. Thank you so much again. :)

@mattbrailsford mattbrailsford added this to the 1.5.2 milestone Mar 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants