This is a migrated thread and some comments may be shown as answers.

[Solved] Custom created PanelBar items crash in SP1

0 Answers 68 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Joan Vilariño
Top achievements
Rank 2
Joan Vilariño asked on 19 May 2010, 02:58 PM
Hi

As I told you in a previous post, we need to bind a MvcSiteMap to a PanelBar. This as you said, is not supported, so I made a PanelBuilder function that would bind my items like this:

        public static PanelBarBuilder BindToMvcSitemap(this PanelBarBuilder panelbar, SiteMapNode nodo) 
        { 
            if (nodo != null) 
            { 
                var component = panelbar.ToComponent(); 
                IList<PanelBarItem> items = component.Items; 
                var rootItem = new PanelBarItem() {Enabled = trueVisible = trueExpanded = trueText = nodo.Title}; 
                foreach (MvcSiteMapNode subnodo in nodo.ChildNodes) 
                    if (MostrarNodo(subnodo)) 
                        rootItem.Items.Add(ObtenerNodoMvcSitemap(subnodo as MvcSiteMapNode)); 
                items.Add(rootItem); 
            } 
            return panelbar; 
        } 

The method that creates each item in the panel bar is as follows:

        private static PanelBarItem ObtenerNodoMvcSitemap(MvcSiteMapNode nodo) 
        { 
            if (nodo != null) 
            { 
                var result = new PanelBarItem(); 
                result.Text = nodo.Title; 
                if (!nodo.HasChildNodes || !TieneHijosVisibles(nodo)) 
                { 
                    if (!string.IsNullOrEmpty(nodo.Action)) 
                        result.ActionName = nodo.Action; 
                    if (!string.IsNullOrEmpty(nodo.Controller)) 
                        result.ControllerName = nodo.Controller; 
                    // string.Join("/", new string[] { nodo.Area, nodo.Controller }); 
                    if (!string.IsNullOrEmpty(nodo.Url)) 
                        result.Url = nodo.Url; 
 
                } 
                result.ImageUrl = nodo.ImageUrl; 
                result.Expanded = false
                result.Visible = true
                if (nodo.HasChildNodes) 
                    foreach (MvcSiteMapNode subnodo in nodo.ChildNodes) 
                        if (MostrarNodo(subnodo)) 
                            result.Items.Add(ObtenerNodoMvcSitemap(subnodo as MvcSiteMapNode)); 
                return result; 
            } 
            else return new PanelBarItem();  // This shouldn't happen
        } 

We use it in our master page as follows:

              <%= 
                    Html.Telerik().PanelBar() 
                        .Name("PanelBarMenu") 
                        .ExpandMode(PanelBarExpandMode.Single) 
                        .BindToMvcSitemap(TelerikCirsaExtensions.GetParentLevel(SiteMap.CurrentNode, 1)) 
                %> 

This code worked ok with Q1, but today we upgraded binaries to SP1 and we get a crash ONLY when the result comes from a RedirectToAction call from the controller. I have debugged my code all the way with no error on it... but maybe we're not filling some properties in the PanelBar items that now you require to be filled.

This is the Stack Trace for the crash:

Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código.  
 
Detalles de la excepción: System.NullReferenceException: Referencia a objeto no establecida como instancia de un objeto. 
 
Error de código fuente:  
 
 
Línea 104:            <div id="panelMenu"
Línea 105:                <%= 
Línea 106:                    Html.Telerik().PanelBar() 
Línea 107:                        .Name("PanelBarMenu") 
Línea 108:                        .ExpandMode(PanelBarExpandMode.Single) 
  
 
Archivo de origen: c:\CirsaTFS\Slot\Proyecto\Aplicaciones\GMXNET.Parque\Cirsa.Slot.Cliente.Web\Views\Shared\Site.Master    Línea: 106  
 
Seguimiento de la pila:  
 
 
[NullReferenceException: Referencia a objeto no establecida como instancia de un objeto.] 
   Telerik.Web.Mvc.Infrastructure.Implementation.AuthorizeAttributeCache.GetAuthorizeAttributes(RequestContext requestContext, String controllerName, String actionName) +230 
   Telerik.Web.Mvc.Infrastructure.Implementation.ControllerAuthorization.IsAccessibleToUser(RequestContext requestContext, String controllerName, String actionName) +171 
   Telerik.Web.Mvc.Infrastructure.Implementation.NavigationItemAuthorization.IsAccessibleToUser(RequestContext requestContext, INavigatable navigationItem) +269 
   Telerik.Web.Mvc.UI.<>c__DisplayClass2`1.<IsAccessible>b__1(T item) +76 
   System.Linq.Enumerable.Any(IEnumerable`1 source, Func`2 predicate) +159 
   Telerik.Web.Mvc.UI.NavigatableExtensions.IsAccessible(IEnumerable`1 items, INavigationItemAuthorization authorization, ViewContext viewContext) +321 
   Telerik.Web.Mvc.UI.PanelBar.WriteItem(PanelBarItem item, IHtmlNode parentTag, IPanelBarHtmlBuilder builder) +486 
   Telerik.Web.Mvc.UI.<>c__DisplayClass9.<WriteItem>b__6(PanelBarItem child) +63 
   Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each(IEnumerable`1 instance, Action`1 action) +230 
   Telerik.Web.Mvc.UI.PanelBar.WriteItem(PanelBarItem item, IHtmlNode parentTag, IPanelBarHtmlBuilder builder) +653 
   Telerik.Web.Mvc.UI.<>c__DisplayClass9.<WriteItem>b__6(PanelBarItem child) +63 
   Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each(IEnumerable`1 instance, Action`1 action) +230 
   Telerik.Web.Mvc.UI.PanelBar.WriteItem(PanelBarItem item, IHtmlNode parentTag, IPanelBarHtmlBuilder builder) +653 
   Telerik.Web.Mvc.UI.<>c__DisplayClass4.<WriteHtml>b__3(PanelBarItem item) +110 
   Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each(IEnumerable`1 instance, Action`1 action) +230 
   Telerik.Web.Mvc.UI.PanelBar.WriteHtml(HtmlTextWriter writer) +438 
   Telerik.Web.Mvc.UI.ViewComponentBase.Render() +147 
   Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.Render() +55 
   Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToString() +28 
   System.Web.HttpWriter.Write(Object obj) +22 
   System.Web.Mvc.SwitchWriter.Write(Object value) +15 
   System.Web.UI.HtmlTextWriter.Write(Object value) +31 
   ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\CirsaTFS\Slot\Proyecto\Aplicaciones\GMXNET.Parque\Cirsa.Slot.Cliente.Web\Views\Shared\Site.Master:106 
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256 
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10 
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29 
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +59 
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266 
 
  
 

Hope all of this info will help you narrow the problem.

Thanks!!!
Tags
PanelBar
Asked by
Joan Vilariño
Top achievements
Rank 2
Share this question
or