Reputation: 2745
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
Upvotes: 2
Views: 514
Reputation: 2745
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());
}))
Upvotes: 3