ASP. NET MVC View engine

Source: Internet
Author: User

Following the introduction of razor last week, ASP. NET MVC now has four main view engines. The other three engines are spark, NHAML, and legacy aspx file templates. This article will outline these four engines and focus on the new razor engine.

The ASPX-style view engine can be traced back to the remote ASP. Using <%=%> and <%: The placeholder for%> syntax occupies a dominant position in such styles. Over time, the ASPC control is added, followed by the master page, but it also brings an expensive page life cycle.

Spark, also used in the monorail of the Castle project, takes a slightly different approach. It supports both placeholders and the ability to mix HTML and code without restrictions with special attributes and tags. It may be cumbersome, but it has the advantage of being fully XML-compatible.

Nhaml is a. NET implementation of the Haml markup language. This language does not use XML-style syntax at all. With a shorthand syntax, it eliminates a lot of syntactic noise in the previous style (XML), such as ending tags.

The latest view engine is Microsoft's Razor. While all templating systems have some common features, Razor is quite different from the three view engines we discussed earlier. Unlike Nhaml,razor, XML tags are still used, but unlike Spark,razor, which does not go so far in terms of using XML code. It is also not exactly like ASPX, because it replaces the more cumbersome placeholders with the @ sign-on expression or the normal control block. Because no special closing tag is required, the final code of razor is concise.

By default, all text generated from the @ expression is HTML-encoded "to prevent XSS attacks." The text inside the @ block can contain multiple "HTML content blocks". When any XML tag is identified, razor switches back to HTML mode, very similar to the technique used by traditional ASP developers to "%> HTML code <%=". If you actually don't want the XML tag to switch back to HTML mode, you can use <text> as a placeholder.

Because Razor uses the existing VB or C # syntax, Microsoft expects it to be easy to learn. Any text editor can be used to edit the razor file, and Visual Studio 2010 will also add updates to the full support for Razor file smart hints.

Another important feature of Razor is its compatibility with the unit test framework. The razor template does not require a controller or Web server as host (host), so the view written out with it should be fully measurable. For ASPX, although theoretically everything can be tested, it is actually quite difficult, while the other two engines don't even really mention testability on their websites.

Four view engines support the concept of master pages, so there's not much to talk about here. ASPX provides only partial support for precompiling views into assembly files, while Razor and spark are fully supported. Nhaml currently puts this in the list of requirements features. It is particularly interesting that razor and spark pre-compiled views can be used in a non-hosted scenario, such as a mail merge engine.
View English Original : Four view Engines for ASP.

ASP. NET MVC View engine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.