Part 3 - Using custom view engines with asp.net mvc
2016-10-14 15:40
441 查看
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是空的,如下图:
![](https://img-blog.csdn.net/20161014155043197?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
如果希望他能像另外两个ViewEngine一样,有Create, Delete等Template, 只需要把他们的文件Create.tt, Delete.tt等文件拷贝到Spark文件夹即可。
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文件夹即可。
相关文章推荐
- ASP.NET MVC- VIEW Using the TagBuilder Class to Build HTML Helpers Part 3
- ASP.NET MVC- VIEW Creating Page Layouts with View Master Pages Part 4
- Part 2 - View engines in asp.net mvc
- ASP.NET MVC- VIEW Creating Custom HTML Helpers Part 2
- 【转】ASP.NET MVC 3 Service Location, Part 3: View Engines/View Pages
- Using StructureMap with the ASP.NET MVC framework
- 【翻译】Building a Simple Blog Engine with ASP.NET MVC and LINQ - Part 2
- http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
- Using jQuery with the ASP.NET CustomValidator Control(转)
- NVelocity View Engine with Asp.net Mvc
- Exception handling with custom error pages in ASP.NET using C#.
- ASP.NET MVC - Displaying Images using Custom Html Helper Method
- HTML5, jQuery Mobile and ASP.NET MVC 4 – Using the ViewModel between the model and controller
- 【ASP.NET Step by STep】之九 Master/Detail Filtering Across Two Pages 之十 Master/Detail Using a Selectable Master GridView with a Details DetailView
- [转]Using the HTML5 and jQuery UI Datepicker Popup Calendar with ASP.NET MVC - Part 4
- Using jQuery Grid With ASP.NET MVC
- ASP.NET MVC 2 Templates, Part 4: Custom Object Templates[翻译]
- 【翻译】Building a Simple Blog Engine with ASP.NET MVC and LINQ - Part 4
- 【翻译】Building a Simple Blog Engine with ASP.NET MVC and LINQ - Part 1
- Multiple Models in a View in ASP.NET MVC 4 / MVC 5 (with source code)