asp.net-mvc - 将 T4MVC 和 Kendo UI 用于 ASP.NET MVC

标签 asp.net-mvc kendo-ui kendo-asp.net-mvc t4mvc

如何将 T4MVC 模板与 Kendo UI 帮助器一起用于 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

我收到一条错误消息:

'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

最佳答案

我找到了这个article并修改了解决方案。

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;
    }
}

用法如下所示:

@(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());
      }))

关于asp.net-mvc - 将 T4MVC 和 Kendo UI 用于 ASP.NET MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29340986/

相关文章:

php - 来自 MySQL sql 查询的 kendo-ui 网格日期格式

c# - Kendo Grid 将所有数据打印到 Excel,而不仅仅是可见数据

javascript - 使用 ASP.NET MVC 中的 Kendo UI ComboBox 对数字数组进行过滤

javascript - Kendo ASP.Net MVC Datagrid 如何在子行中获取父行 ID

jquery - 剑道窗口 : prevent adjusting content to the window size

asp.net-mvc - Adobe Flash 和 ASP.NET 中的集成授权/身份验证

asp.net-mvc - 本地集群上托管的 Service Fabric 托管 Asp.net WebApi 容器应用程序 : 403 - Forbidden : Access is denied.

javascript - Internet Explorer 9 中多次触发单击事件

c# - 如何使用范围数据注释属性指定最小但没有最大小数?

javascript - 如何设置图表工具提示的模板文件?