使用 T4MVC 和 Kendo UI 用于 ASP.NET MVC
Using T4MVC and Kendo UI for ASP.NET MVC
如何将 T4MVC 模板与 Kendo UI 助手一起用于 ASP.NETMVC?
@(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());
}))
如何将 T4MVC 模板与 Kendo UI 助手一起用于 ASP.NETMVC?
@(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());
}))