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

[Solved] ViewData doesn't populate sitemap after OnException

0 Answers 31 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.
Anand
Top achievements
Rank 1
Anand asked on 07 Oct 2010, 01:48 AM
Hi,
     I am using PopulateSiteMap attribute on my base controller and binding the menu to sitemap in master page as below -

<%

 

=Html.Telerik().Menu().Name("mainMenu").BindTo("siteMap")%>

 


I am loading SiteMap in global.asax.cs file on Application_Start as

((

 

XmlSiteMap)SiteMapManager.SiteMaps.DefaultSiteMap).Load();

Everything works fine except when there is an exception. In case of exception I handle it in BaseController's OnException handler and return View() in there. In this case, menu binding breaks in masterpage throwing error "You must have SiteMap defined with key "siteMap" in ViewData dictionary".

How can I populate sitemap in ViewData dictionary in case of exception?
 Below is code I'm using for OnException.

 

 

 

protected override void OnException(ExceptionContext filterContext)

 

{

 

 

    base.OnException(filterContext);

 

 

 

    if (filterContext.Exception != null)

 

    {

 

 

       this.ViewData["ErrorDetails"] = filterContext.Exception.Message;

 

       filterContext.Result = View();

       filterContext.ExceptionHandled = true;
   

 

}

 

 

}

Thanks,
Anand

Tags
Menu
Asked by
Anand
Top achievements
Rank 1
Share this question
or