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

Error binding to site map

8 Answers 165 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rich H
Top achievements
Rank 1
Rich H asked on 05 Aug 2010, 01:32 PM
Hi

I am currently looking into using the Telerik ASP.NET MVC controls in an upcoming project and have been looking at the Menu control. I have put together a small prototype to see how it works but have have been getting an issue binding to the site map in certain scenarios. Firstly my environment is a virtual machine: Win2003, .NET 3.5, VS2008 with C#, and I'm using version 2010.1.408.235 of the Telerik ASP.NET MVC controls and IE7.

I have created a prototype MVC app with a couple of controllers and I have added a couple of Areas with a controller and view in each. There is nothing in the way of functionality, just testing the navigation. I have created the following site map:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
   <siteMapNode title="Home" controller="Home" action="Index">
      <siteMapNode title="Main">
         <siteMapNode controller="Reports" action="Jobs" title="Jobs" />
         <siteMapNode controller="Reports" action="Details/1000" title="Details" />
      </siteMapNode>
      <siteMapNode title="Test">
         <siteMapNode area="Test" controller="Reference" action="Index" title="Data" />
      </siteMapNode>
      <siteMapNode title="Monitoring">
         <siteMapNode area="Monitoring" controller="Jobs" action="Index" title="Jobs" />
      </siteMapNode>
   </siteMapNode>
</siteMap>

I am registering the site map in the global.asax.cs file as follows:
protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    RegisterRoutes(RouteTable.Routes);
    // Register where Telerik control specific css and scripts are located
    WebAssetDefaultSettings.StyleSheetFilesPath = "~/Content/Telerik";
    WebAssetDefaultSettings.ScriptFilesPath     = "~/Scripts/Telerik";
   // Register site map so that it can be bound to the Telerik Menu control
    SiteMapManager.SiteMaps.Register<XmlSiteMap>("Main", sitmap => sitmap.LoadFrom("~/Main.sitemap"));
}

and then in the site master file I render the Menu control as follows:
<% 
   Html.Telerik().Menu().Name("MainMenu").BindTo("Main").Render();         
%>

When I run this (from Visual Studio) and navigate to either of the controller actions under the Main menu item I am presented with the relevant view and the Menu renders correctly and if you hover the mouse over any of the menu items the correct URL is displayed in the browser status bar. However, if I then select either of the items under the Test or Monitoring Menu items (where the controllers / views reside in ASP.NET MVC Areas) then an error is returned as follows:
Server Error in '/' Application.
--------------------------------------------------------------------------------
  
Object reference not set to an instance of an object
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  
Source Error: 
  
  
Line 39:             Type controllerType = controllerTypeCache.GetControllerType(requestContext, controllerName);
Line 40: 
Line 41:             IDictionary<string, IEnumerable<AuthorizeAttribute>> map = GetOrCreate(controllerType.TypeHandle, () => GetInternal(controllerType, actionMethodCache.GetAllActionMethods(requestContext, controllerName)));
Line 42: 
Line 43:             IEnumerable<AuthorizeAttribute> attributes;
   
  
Source File: E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\Infrastructure\Implementation\AuthorizeAttributeCache.cs    Line: 41 
  
Stack Trace: 
  
  
[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.Mvc.Infrastructure.Implementation.AuthorizeAttributeCache.GetAuthorizeAttributes(RequestContext requestContext, String controllerName, String actionName) in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\Infrastructure\Implementation\AuthorizeAttributeCache.cs:41
   Telerik.Web.Mvc.Infrastructure.Implementation.ControllerAuthorization.IsAccessibleToUser(RequestContext requestContext, String controllerName, String actionName) in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\Infrastructure\Implementation\ControllerAuthorization.cs:57
   Telerik.Web.Mvc.Infrastructure.Implementation.NavigationItemAuthorization.IsAccessibleToUser(RequestContext requestContext, INavigatable navigationItem) in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\Infrastructure\Implementation\NavigationItemAuthorization.cs:38
   Telerik.Web.Mvc.UI.<>c__DisplayClass2`1.<IsAccessible>b__1(T item) in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\UI\NavigatableExtensions.cs:188
   System.Linq.Enumerable.Any(IEnumerable`1 source, Func`2 predicate) +159
   Telerik.Web.Mvc.UI.NavigatableExtensions.IsAccessible(IEnumerable`1 items, INavigationItemAuthorization authorization, ViewContext viewContext) in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\UI\NavigatableExtensions.cs:188
   Telerik.Web.Mvc.UI.Menu.WriteItem(MenuItem item, IHtmlNode parentTag, IMenuHtmlBuilder builder) in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\UI\Menu\Menu.cs:189
   Telerik.Web.Mvc.UI.<>c__DisplayClass4.<WriteHtml>b__3(MenuItem item) in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\UI\Menu\Menu.cs:164
   Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each(IEnumerable`1 instance, Action`1 action) in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\Extensions\EnumerableExtensions.cs:63
   Telerik.Web.Mvc.UI.Menu.WriteHtml(HtmlTextWriter writer) in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\UI\Menu\Menu.cs:164
   Telerik.Web.Mvc.UI.ViewComponentBase.Render() in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\UI\ViewComponentBase.cs:166
   Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.Render() in E:\Installs\telerikaspnetmvc\408\Source\Telerik.Web.Mvc\UI\ViewComponentBuilderBase.cs:136
   ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in e:\Projects\Sandbox\EtlJobMonitoring\EtlJobMonitoring\Views\Shared\Site.Master:28
   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
  
   
  
  
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082

Now, if I change the site map and use the url attribute instead of the area, controller, and action attributes then everything works fine.

I'm not sure if this is down to me not setting up the site map file correctly or whether it is down to something else but I would really appreciate any help in trying to understand this behaviour.

Thanks...


8 Answers, 1 is accepted

Sort by
0
Rich H
Top achievements
Rank 1
answered on 10 Aug 2010, 03:51 PM
Update... the latest version (2010.2.713.235) of the Telerik MVC controls resolves this issue.
0
mohit
Top achievements
Rank 1
answered on 19 Aug 2010, 06:04 PM
I have Updated latest version of grid now its insert mode not working can you please tell

Thanks,
Mohit
0
Eric Swanson
Top achievements
Rank 1
answered on 02 Sep 2010, 08:12 PM
I also have done the same thing.....with the same error.

Using the newest version of Telerik MVC(2010.2.825) with VS2010 and .NET 4.0

0
Atanas Korchev
Telerik team
answered on 03 Sep 2010, 07:45 AM
Hello Eric Swanson,

 We need a sample project reproducing the exception. In order to do so you can submit a support ticket or use a public file hosting web site such as dropbox.com or skydrive.com.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Atanas Korchev
Telerik team
answered on 03 Sep 2010, 07:46 AM
Hello Eric Swanson,

 We need a sample project reproducing the exception. In order to do so you can submit a support ticket or use a public file hosting web site such as dropbox.com or skydrive.live.com.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
viktor
Top achievements
Rank 1
answered on 23 Sep 2010, 01:07 PM
Hi

I have same problem and have attached sample project.

Regards
0
Georgi Krustev
Telerik team
answered on 24 Sep 2010, 11:56 AM
Hello segun,

The aforementioned error is expected. The sample.sitemap contains incorrect Action and Controller attributes, which will cause the exception. When you set action and controller attributes to SiteMapNode you should be sure that UrlHelper (built-in ASP.NET MVC) could generate correct URL. If you need to navigate to custom URL, you should use url attribute.

For your convenience I have attached the modified test project, which shows how to construct correctly SiteMap.

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
viktor
Top achievements
Rank 1
answered on 24 Sep 2010, 12:18 PM
Many thanks

I actually found out earlier this morning that "bindto" fails if the relevant controllers and actions are invalid.
Many thanks for your response, though. Good job.
Tags
Menu
Asked by
Rich H
Top achievements
Rank 1
Answers by
Rich H
Top achievements
Rank 1
mohit
Top achievements
Rank 1
Eric Swanson
Top achievements
Rank 1
Atanas Korchev
Telerik team
viktor
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or