【问题标题】:Using T4MVC and Kendo UI for ASP.NET MVC为 ASP.NET MVC 使用 T4MVC 和 Kendo UI
【发布时间】:2015-03-30 07:53:08
【问题描述】:

如何将 T4MVC 模板与 ASP.NET MVCKendo UI 助手一起使用?

@(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

【问题讨论】:

  • 能否将相关代码添加到您的问题中,这可能有助于理解您的问题

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


【解决方案1】:

我找到了这个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());
      }))

【讨论】:

  • @Vash,我只能明天做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多