Using T4MVC and Kendo UI for ASP.NET MVC

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

How to use T4MVC templates with Kendo UI helpers for ASP.NET MVC?

@(Html.Kendo()   .Grid<SomeModel>()   .Name("T4Grid")   .Columns(col =>   {       col.Bound(wf => wf.Name);       col.Bound(wf => wf.Description);   })   .DataSource(src => src       .Ajax()       .Read(read => read.Action(MVC.Area.Controller.Action())))) // <= an error here

I have an error message:

'Kendo.Mvc.UI.Fluent.CrudOperationBuilder' does not contain a definition for 'Action' and the best extension method overload 'Kendo.Mvc.UI.NavigatableExtensions.Action( Kendo.Mvc.INavigatable, System.Web.Routing.RouteValueDictionary)' has some invalid arguments

回答1:

I have found this article and modified the solution.

using System; using System.Web.Mvc; using Kendo.Mvc; using Kendo.Mvc.UI; using Kendo.Mvc.UI.Fluent;  public static class NavigationItemBuilderExtensions {     public static NavigationItemBuilder<TItem, TBuilder> Action<TItem, TBuilder>         (this NavigationItemBuilder<TItem, TBuilder> instance, ActionResult action)         where TItem : NavigationItem<TItem>         where TBuilder : NavigationItemBuilder<TItem, TBuilder>, IHideObjectMembers     {         return Action<NavigationItemBuilder<TItem, TBuilder>>(instance, action);     }      public static CrudOperationBuilderBase<TBuilder> Action<TBuilder>         (this CrudOperationBuilderBase<TBuilder> instance, ActionResult action)         where TBuilder : CrudOperationBuilderBase<TBuilder>, IHideObjectMembers     {         return Action<CrudOperationBuilderBase<TBuilder>>(instance, action);     }      private static TResult Action<TResult>(dynamic instance, ActionResult action)     {         if (instance == null)         {             throw new ArgumentNullException("instance");         }          var actionResult = action as IT4MVCActionResult;         if (actionResult == null)         {             throw new NotSupportedException(                 "An argument action must implement IT4MVCActionResult interface.");         }          instance.Action(             actionResult.Action,             actionResult.Controller,             actionResult.RouteValueDictionary);          return instance;     } }

A usage shown below:

@(Html.Kendo()       .Grid<SomeModel>()       .Name("T4Grid")       .Columns(col =>       {           col.Bound(wf => wf.Name);           col.Bound(wf => wf.Description);       })       .DataSource(src => src           .Ajax()           .Read(read => read.Action(MVC.SomeArea.SomeController.SomeAction()))))  @(Html.Kendo()       .PanelBar()       .Name("T4PanelBar")       .Items(bar =>       {           bar.Add().Text("Index").Action(MVC.SomeArea.SomeController.SomeAction());           bar.Add().Text("Another").Action(MVC.SomeArea.SomeController.SomeAction2());       }))


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!