2012-09-24 35 views
0

已經在我的MVC項目中成功使用了kendo,並且決定添加ImageResizer。一旦我安裝ImageResizer以及它通過nuget MvcRoutingShim,它打破了我的劍道菜單。這是一個相當基本的菜單:telerik kendo在MVC中使用ImageResizer嗎?

Html.Kendo().Menu().Name("Menu").BindTo(Html.MvcSiteMap(provName).Provider.RootNode.ChildNodes, 
        mappings => mappings.For<MvcSiteMapNode>(binding => binding 
         .ItemDataBound((item, node) => 
         { 
           item.ActionName = node.Action; 
           item.ControllerName = node.Controller; 
           item.RouteValues.Add("area", node.Area); 
         }) 
          .Children(node => node.ChildNodes))) 
       .Render(); 

,但是當我嘗試運行,我得到一個

The method or operation is not implemented 

例外,隨着follwing堆棧跟蹤:

at System.Web.HttpContextBase.get_Items() 
    at ImageResizer.Plugins.MvcRoutingShim.StopRoutingRoute.GetRouteData(HttpContextBase httpContext) 
    at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) 
    at Kendo.Mvc.Infrastructure.Implementation.RouteDataCache.RouteDataFactory(String url) 
    at Kendo.Mvc.Infrastructure.Implementation.RouteDataCache.<GetRouteData>c__AnonStorey1B.<>m__26() 
    at Kendo.Mvc.Infrastructure.Implementation.NoCache.Get[T](String key, Func`1 defaultValueFactory) 
    at Kendo.Mvc.Infrastructure.Implementation.RouteDataCache.GetRouteData(String key, String url) 
    at Kendo.Mvc.Infrastructure.Implementation.AuthorizationContextCache.GetAuthorizationContext(RequestContext request, String controllerName, String actionName, RouteValueDictionary routeValues) 
    at Kendo.Mvc.Infrastructure.Implementation.ControllerAuthorization.IsAccessibleToUser(RequestContext requestContext, String controllerName, String actionName, RouteValueDictionary routeValues) 
    at Kendo.Mvc.Infrastructure.Implementation.NavigationItemAuthorization.IsAccessibleToUser(RequestContext requestContext, INavigatable navigationItem) 
    at Kendo.Mvc.UI.NavigatableExtensions.IsAccessible(INavigatable item, INavigationItemAuthorization authorization, ViewContext viewContext) 
    at Kendo.Mvc.UI.NavigationItemContainerExtensions.WriteItem[TComponent,TItem](TItem item, TComponent component, IHtmlNode parentTag, INavigationComponentHtmlBuilder`1 builder) 
    at Kendo.Mvc.UI.Menu.<WriteHtml>c__AnonStorey71.<>m__1FC(MenuItem item) 
    at Kendo.Mvc.Extensions.EnumerableExtensions.Each[T](IEnumerable`1 instance, Action`1 action) 
    at Kendo.Mvc.UI.Menu.WriteHtml(HtmlTextWriter writer) 
    at Kendo.Mvc.UI.WidgetBase.Render() 
    at Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.Render() 
    at ASP._Page_Views_Shared__Layout_cshtml.Execute() in c:\Code\StandardProject\4.4.3.0\Server\MVC\CoBRAMVC4Portal\Views\Shared\_Layout.cshtml:line 60 
    at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() 
    at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() 
    at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) 
    at System.Web.WebPages.WebPageBase.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) 
    at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) 
    at System.Web.WebPages.WebPageBase.Write(HelperResult result) 
    at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) 
    at System.Web.WebPages.WebPageBase.PopContext() 
    at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) 
    at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) 
    at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) 
    at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) 
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) 

有其他人得到了劍道來使用imageresizer?

回答

1

看來Kendo正在從MvcRoutingShim請求路由數據,但提供了一個非功能性的HttpContextBase實例。

MvcRoutingShim預計context.Items是可訪問的,但它在這裏拋出一個NotImplementedException。

該文件位於/Core.Mvc/StopRoutingRoute.cs中。

public override RouteData GetRouteData(System.Web.HttpContextBase httpContext) { 
     if (httpContext.Items[_contextItemsFlag] != null) 
      return new RouteData(this, new StopRoutingHandler()); 
     return null; 
    } 

它更改爲

public override RouteData GetRouteData(System.Web.HttpContextBase httpContext) { 
     try{ 
      if (httpContext.Items[_contextItemsFlag] != null) 
       return new RouteData(this, new StopRoutingHandler()); 
     }catch(NotImplementedException){} 

     return null; 
    } 

應該解決的問題,而不會引入副作用。不幸的是,HttpContextBase沒有提供一種在沒有try/catch的情況下'避免'NotImplementedException的方法。類型比較會變得脆弱並且會破壞單元測試,儘管如果httpContext是而不是子類別,額外的「快速退出路徑」可能會加速99%的情況。

+0

爲我修好了!謝謝。 – Phil

相關問題