I've been working to extend the grid system by adding custom settings to the grid editor but I'm having trouble accessing the data from the JSON feed. If a setting has not been applied to a single box in the grid layout nothing is added to the JSON data resulting in a null reference when trying to access the data. Is there a way to ignore null references or another way to accomplish this?
Here is the error message I receive.
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
@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 ) {
<pre>@area.config.backgroundColor</pre>
<div class="col-md-@area.grid column" @RenderElementAttributes(area)>
<div class="color-bg"></div>
<div class="inner">
@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>
}
If I change the @area.config.backgroundColor to @area.config I can see the data in the front end but when I want to display the data for backgroundColor I get an error since not all boxes have a custom setting applied in the back office.
Here's an example of the data with a setting applied for backgroundColor
can you not wrap your request for the backgroundColor config setting in an if which first checks the truthy value of hasConfig just noting the difference in json in working and non working blocks. If there is no config and therefore an error is a bout to be thrown the value of hasConfig will be false otherwise true.
JSON null reference extending grid system
I've been working to extend the grid system by adding custom settings to the grid editor but I'm having trouble accessing the data from the JSON feed. If a setting has not been applied to a single box in the grid layout nothing is added to the JSON data resulting in a null reference when trying to access the data. Is there a way to ignore null references or another way to accomplish this?
Here is the error message I receive.
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
If I change the @area.config.backgroundColor to @area.config I can see the data in the front end but when I want to display the data for backgroundColor I get an error since not all boxes have a custom setting applied in the back office.
Here's an example of the data with a setting applied for backgroundColor
And here is an example of a box that does not have a setting applied for backgroundColor. These boxes are causing the error.
can you not wrap your request for the backgroundColor config setting in an if which first checks the truthy value of hasConfig just noting the difference in json in working and non working blocks. If there is no config and therefore an error is a bout to be thrown the value of hasConfig will be false otherwise true.
That worked. Thanks.
is working on a reply...
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.