Search code examples
asp.net-mvcrazorviewengine

ASP.NET MVC Razor view engine


After reading Scott Guthrie's blog entry about the new Razor view engine for ASP.NET MVC and reading this question comparing the available view engines.

Razor seems to address most of the problems with the default view engine. What feature differences would make it a compelling choice for you as a developer? What features are lacking that would keep you from using it?


Solution

  • There's much more to view engine except markup language. Few Spark features that I will miss:

    • write html extensions using same markup language, not C# (macros) - I see that Razor also supports this, I hope it supports method/parameters override;
    • custom tags (write _Tag.spark to use <Tag />);
    • autogenerated variables like varIsFirst, varIndex, etc;
    • special expression forms (?{} for conditional attributes, $!{} to skip errors, etc);
    • nice master/partial layouts support, including ability to specify in partial that part of markup should be render only once in master (e.g. script includes);
    • you can still have WebForms markup - great for compatibility and incremental upgrade;
    • support to use both "" and '' quotes inside each other (extremely useful).

    I like Spark syntax for loops/ifs more - mixing HTML <> and C# {} braces doesn't look too nice - but that's purely personal opinion.

    There're very promising features in Razor, too, e.g. inline templates. Given that Spark creator was hired by Microsoft, I think there's a hope for Razor to be well written, very useful, and well supported view engine. Of course I won't re-write hundreds of my Spark views with Razor (though I did rewrite dozens of my WebForms views with Spark). But I will surely take a serious look at Razor - I only found this out from your questions, thanks - and what I see now looks promising. It doesn't compete with WebForms, of course (any view engine is better than WebForms), but it looks like a good choice for a new ASP.NET MVC project, if you haven't yet invested into another view engine too much.