Last month Scott Guthrie announced a new ASP.NET View Engine called Razor. Then Microsoft released the beta of a new product called WebMatrix which was utilizing it. It also employed a new web framework called ASP.NET Web Pages. Then yours truly made a few attempts to use Telerik Extensions for ASP.NET MVC in a WebMatrix page. The end result was promising. I waited for official Razor support in ASP.NET MVC 3. Then Scott “Almighty” Guthrie announced the first preview of ASP.NET MVC 3 which includes Razor support. This week I started to see how to improve Telerik’s Razor story… This blog post shows the end result.
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.
Follow these steps:
@using Telerik.Web.Mvc.UI
@Html.Telerik().StyleSheetRegistrar().DefaultGroup(g => g.Add("telerik.common.css").Add("telerik.vista.css"))
@Html.Telerik().PanelBar().Name("PanelBar").Items(items =>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:
{
items.Add()
.Text("Razor Inline Template")
.Content(@<strong>Hello World from Razor!!!</strong>)
.Expanded(true);
})
@(Html.Telerik()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.
.PanelBar()
.Name("PanelBar")
)
@Html.Telerik().ScriptRegistrar()