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)

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

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1410 | Hits: 31

Similar Posts

  • Telerik Introduces Free Web Testing Framework for ASP.NET AJAX and Silverlight more
  • ASP.NET MVC 2.0 and VS 2010 plan now public more
  • You should NOT use ASP.NET MVC if. . . more
  • Telerik.Charting in RadControls for ASP.NET AJAX Q3 2008 more
  • Visual Studio 2008 Intellisense and Telerik.Charting more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD