Advanced View Engines
Scott Hanselman, community program manager at Microsoft, likes to call the view engine “just an angle bracket generator.” In the simplest terms, that's exactly what it is. A view engine will take an in-memory representation of a view and turn it into whatever other format you like. Usually, this means that you will create a cshtml file containing markup and script, and ASP.NET MVC's default view engine implementation, the RazorViewEngine, will use some existing ASP.NET APIs to render your page as HTML.
View engines aren't limited to using cshtml pages, nor are they limited to rendering HTML. You'll see later how you can create alternate view engines that render output that isn't HTML, as well as unusual view engines that require a custom DSL (domain-specific language) as input.
To better understand what a view engine is, let's review the ASP.NET MVC life cycle (very simplified in Figure 15.8).
A lot more subsystems are involved than Figure 15.8 shows; this figure just highlights where the view engine comes into play — which is right after the Controller action is executed and returns a ViewResult in response to a request.
It is very important to note here that the controller itself does not render the view; it simply prepares the data (that is, the model) and decides which view to display by returning a ViewResult instance. As you saw earlier ...
Get Professional ASP.NET MVC 4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.