Archive for the ‘Razor’ Category

The Razor View Engine

February 15th, 2011 No comments

One of the features in the recently released ASP.NET MVC 3 is the brand new Razor view engine, which ScottGu has blogged about a lot lately.

I’ve been searching for the advantages of using Razor versus the standard ASP.NET WebForms syntax, and after reading this thread in StackOverflow and the quick syntax reference posted by Phil Haack my conclusion is that the biggest one is the conciseness of the syntax. There’s probably not much value in switching to it if you already have a lot of ASPX views (even though there’s a tool that can help you with the conversion), but it could be an interesting choice for a new project.

Having said this, one of the stated design goals for Razor according to ScottGu is to make it unit testable, which could be interesting depending on how complex it is to do it in practice. I searched for examples and (again) found a question about it on StackOverflow. Andrew Nurse, one of the developers that designed and wrote Razor, answered suggesting to compile the Razor views, “load the generated class, pass in the mocked out context objects, and call Execute()”. This is far more complex than I’d would like it to be, but I expect things to get simpler in the upcoming releases.

Well, it’s time to get back to work. Happy coding!

Categories: .NET, ASP.NET MVC, MVC, Razor Tags: , , ,