Part 31 Using custom view engines with asp net mvc04:33

  • 0
Published on January 18, 2018

Out of the box ASP.NET MVC supports the following 2 view engines
1. ASPX
2. Razor

In addition to the above 2 view engines, there are several custom view engines that can be used with asp.net mvc. The following are a few of these custom view engines.
1. Spark
2. NHaml
3. SharpDOM
4. Brail

For example, if you want to use Spark as the view engine for your asp.net mvc 4 project, then install Spark.Web.Mvc4 using NuGet Package Manager.

At this point, right click on any controller action method and select “Add View” from the context menu. Notice that, “View Engine” dropdownlist in “Add View” dialog box only shows – Razor and ASPX view engines. If you want the “Spark” view engine to be listed, then, we need to register “Spark View Engine” templates.

Step 1: Navigate to the following path and create a folder with name=”Spark”. Spark specific templates must be copied into “Spark” folder.
C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEItemTemplatesCSharpWebMVC 4CodeTemplatesAddView

Step 2: Create an xml file with in “Spark” folder. The name of the XML file must be “ViewEngine.xml” and must contain the following xml content.
[?xml version=”1.0″ encoding=”utf-8″ ?]
[ViewEngine DisplayName=”Spark”
ViewFileExtension=”.spark”
DefaultLayoutPage=”~/Views/Shared/_Layout.spark”
PartialViewFileExtension=”.spark” /]

Now, right click on any controller action method and select “Add View” from the context menu. Notice that, “Spark” view engine is also listed.

Text version of the video

Slides

All ASP .NET MVC Text Articles

All ASP .NET MVC Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

Enjoyed this video?
"No Thanks. Please Close This Box!"