This question is locked. New answers and comments are not allowed.
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:
I am registering the site map in the global.asax.cs file as follows:
and then in the site master file I render the Menu control as follows:
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:
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...
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...