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