Using T4MVC strongly-typed helpers with Telerik Extensions for ASP.NET MVC
Posted by: the telerik blogs,
on 05 Nov 2009 |
View original | Bookmarked: 0 time(s)
If you want fast and strongly-typed access to your controller actions, the T4 helpers by David Ebbo are a real treasure. Since we couldnt provide support for them out-of the box (after all, the helper classes are generated), here is a small extension method that allows their usage as shown in the screenshot above:
using
System.Web.Mvc;
using Telerik.Web.Mvc;
using Telerik.Web.Mvc.Infrastructure;
using Telerik.Web.Mvc.UI;
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
{
var t4ActionResult = action as T4MVC_ActionResult;
Guard.IsNotNull(t4ActionResult, "action");
instance.ToItem()
.Action(t4ActionResult.Action,
t4ActionResult.Controller,
t4ActionResult.RouteValues);
return instance;
}
}
Note that the use of generics enables this extension method for all navigation components.
Download the source code