Telerik blogs

 VibrantInk rocks!

 

If you want fast and strongly-typed access to your controller actions, the T4 helpers by David Ebbo are a real treasure. Since we couldn’t provide an 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.


About the Author

Alexander Gyoshev

 is Senior Front-end Developer in Kendo Team

Comments

Comments are disabled in preview mode.