
Using Razor with ASP.NET MVC in Four Easy Steps - tghw
http://stefan.rusek.org/Posts/Using-Razor-with-ASP-NET-MVC-in-Four-Easy-Steps/26/
======
troygoode
While I'm certainly glad that Phil & co are finally replacing the inadequate
WebForms view engine with something better, I'm nonplussed that the "something
better" still isn't at least as good as Spark - especially since Louis (the
creator of Spark) works on the Asp.net team now.

I realize that Spark's fake-HTML-element syntax would not be everyone's
personal favorite (reminders of: Cold Fusion, WebForm server controls), the
fact is that Spark provides a good bit of "value add" on top of the normal
view engine goodness.

Example (in Spark):

    
    
      <ul>
        <li each="var p in Model.Products"
          class="alt?{pIndex%2!=0} isFirst?{pIsFirst} isLast?{pIsLast}">
          Product: ${p.Name}
        </li>
      </ul>
    

Would output:

    
    
      <ul>
        <li class="isFirst">Product: AAA</li>
        <li class="alt">Product: BBB</li>
        <li>Product: CCC</li>
        <li class="alt isLast">Product: DDD</li>
      </ul>
    

The alternation of rows and detection of first/last row is an _extremely_
common scenario for web developers that Spark totally gets right, but so far
Razor just ignores. I'm glad there will be an option for the masses that are
just using whatever is packed in the box, but so far I'm not seeing what all
the fuss is for those of us that long since moved on from the built-in
ViewEngine.

~~~
rbanffy
Interesting. It reminds me of Zope's Page Templates. I find Spark's syntax to
be dirtier, however.

Has anyone implemented ZPT for .NET?

~~~
troygoode
I don't know of any .NET implementation of ZPT.

What makes you find Spark's syntax to be dirtier than ZPT? Is it the fact that
the Spark example I gave isn't valid XHTML like ZPT is? If so, that is simply
out of convenience - Spark also offers a way to use proper XML namespacing to
achieve complete XHTML compliance:

<http://www.sparkviewengine.com/documentation/syntax> (scroll all the way
down)

~~~
rbanffy
Cool.

And yes - the shortcuts are something I frown upon. Template languages should
not be so expressive as to create an incentive to ASP-style coding, nor too
castrated as to prevent you from doing whatever you want. I think ZPT is right
in the middle of the sweet spot.

------
jerhinesmith
At the risk of coming across as "my favorite language/platform is better than
your favorite language/platform", the fact that you have to jump through these
hoops to get Razor working in your ASP.NET MVC app strikes me as anything but
easy (and certainly not intuitive).

Compare this to using haml in RoR:

    
    
      1. gem install haml
      2. vi newfile.html.haml
    

Why again doesn't .NET have a plugin management system analogous to gems? Or
is there one that I just don't know about?

~~~
gokhan
Razor is not a released technology and the article is describing a hack, as
extracting Razor dlls from WebMatrix CTP and manually registering them in your
project.

~~~
jerhinesmith
Ah, that makes a lot more sense. I guess that's my own fault for not doing
enough research before commenting.

