ASP.NET MVC Razor view engine

前端 未结 6 2029
醉梦人生
醉梦人生 2021-01-30 08:49

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

6条回答
  •  北海茫月
    2021-01-30 09:40

    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 );
    • 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.

提交回复
热议问题