I'm performing an ng-if on my li element, to check whether to show it or not.
<li ng-if="@Model.punkt1.ToString().Length > 0">@Model.punkt1</li>
@Model.punkt1 returns a JValue, which i then convert to a string to check the length. This is for a grid editor in Umbraco, razor syntax is used. My scope merely contains the strings:
$scope.control.punkt1;
But I am getting this error when i run the page:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at ASP._Page_app_plugins_mygrideditor_infobox_cshtml.Execute() in c:\Users\thomb\Documents\Visual Studio 2017\Projects\LoevbjergRema1000Umbraco\LoevbjergRema1000Umbraco\LoevbjergRema1000Umbraco\App_Plugins\MyGridEditor\infobox.cshtml:line 8
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, Object model)
at ASP._Page_Views_Partials_grid_editors_base_cshtml.Execute() in c:\Users\thomb\Documents\Visual Studio 2017\Projects\LoevbjergRema1000Umbraco\LoevbjergRema1000Umbraco\LoevbjergRema1000Umbraco\Views\Partials\Grid\Editors\Base.cshtml:line 19
Why am i not able to check the length of my string?
EDIT:
<li ng-show="@Model.punkt1 != null && @Model.punkt1.ToString().Length > 0">@Model.punkt1</li>
<li ng-show="@Model.punkt2 != null && @Model.punkt2.ToString().Length > 0">@Model.punkt2</li>
<li ng-show="@Model.punkt3 != null && @Model.punkt3.ToString().Length > 0">@Model.punkt3</li>
<li ng-show="@Model.punkt4 != null && @Model.punkt4.ToString().Length > 0">@Model.punkt4</li>
<li ng-show="@Model.punkt5 != null && @Model.punkt5.ToString().Length > 0">@Model.punkt5</li>
And my angular controller:
angular.module("umbraco").controller("my.custom.grideditorcontroller", function ($scope) {
$scope.control.heading;
$scope.control.punkt1 = "";
$scope.control.punkt2 = "";
$scope.control.punkt3 = "";
$scope.control.punkt4 = "";
$scope.control.punkt5 = "";
});