The view engine is responsible for creating HTML from your views. Views are usually some kind of mix-up of HTML and a programming language. The pattern behind most of these is called two-step view.
If you have a Web application with many pages, you often want a consistent look and organization to the site. If every page looks different, you end up with a site that users find confusing. You may also want to make global changes to the appearance of the site easily, but common approaches using Template View (350) or Transform View (361) make this difficult because presentation decisions are often duplicated across multiple pages or transform modules. A global change can force you to change several files.
Two Step View deals with this problem by splitting the transformation into two stages. The first transforms the model data into a logical presentation without any specific formatting; the second converts that logical presentation with the actual formatting needed. This way you can make a global change by altering the second stage, or you can support multiple output looks and feels with one second stage each.
In ASP.NET MVC 4 you can select either Razor View Engine or ASPX View Engine.
For example, a code block in ASPX might look like this:
<% foreach(var item in Model) { %> <tr> <td><%: item.Name %></td> </tr> <% } %>
Whereas the Razor equivalent will look like this:
@foreach(var item in Model) { <tr> <td>@item.Name</td>
A view engine is what MVC uses to find and render the views you are requesting from the controller. If you are satisfied with the default routing you probably won’t need to change anything, but let’s say you wanted to have your shared files usually located in root/views/shared to instead be located in root/common, a custom view engine is what you will need to create to be able to do that.
No comments:
Post a Comment