telerik kendo在MVC中使用ImageResizer吗?

时间:2012-09-24 05:02:47

标签: asp.net-mvc kendo-ui imageresizer

在我的MVC项目中成功使用了kendo一段时间,并且还决定添加ImageResizer。一旦我通过nuget安装了ImageResizer以及它的MvcRoutingShim,它就打破了我的剑道菜单。这是一个相当基本的菜单:

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

异常,使用以下堆栈跟踪:

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 个答案:

答案 0 :(得分: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%的场景。