Telerik Extensions for ASP.NET MVC now support the Razor view engine as well as ASP.NET MVC 3 Preview 1. To play with Razor you can use the sample build attached to the blog post. If you plan to use ASP.NET MVC 3 with the older WebForms view engine you can use the current official version for ASP.NET MVC 2. It should work flawlessly.

Using Telerik Extensions for ASP.NET MVC in a Razor view page (.cshtml)

Follow these steps:

Use the build attached to the blog post. DISCLAIMER: This build is for testing purposes only. Official Razor support will be added as part of the upcoming Q2 2010 release. So be warned :)

All components that support templates now can utilize Razor’s inline templates. However there is one important limitation – the @Html.Something() syntax works only with single line statements (the items => { /*code*/ } block does not count as it is part of a single line statement). To use a multiline statement you should use parenthesis:

@(Html.Telerik() .PanelBar() .Name("PanelBar"))

Using parenthesis has a limitation too – the Razor parser cannot see inline templates in this case. Fortunately this would be fixed in a future Razor release.

Add a ScriptRegistrar at the end of your page

@Html.Telerik().ScriptRegistrar()

And that’s all!

As you can see working with single line statements is not very convenient and adding parenthesis may seem strange initially. Let alone you can totally forget to add them. A possible solution would be to implement a “Razor-friendly” API for component definition. It could look like the API suggested in the Razor’ blog post: http://weblogs.asp.net/blogs/scottgu/image_43366964.png. This employs C# 4’s optional parameters. Still we have not decided what to do with this regards and that’s where you can chime in! I would love to hear your feedback with regards to Razor.