Part 3 - Using custom view engines with asp.net mvc

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 etc....

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 14.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddView

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. 

此时Scoffold Template是空的,如下图:


如果希望他能像另外两个ViewEngine一样,有Create, Delete等Template, 只需要把他们的文件Create.tt, Delete.tt等文件拷贝到Spark文件夹即可。







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值