Use Razor template engine and mvcrazor template engine from MVC
About Razor template engine
1.Introduction
Template engine: Razor, Nveocity, and Vtemplate. Razor has an automatic VS prompt. It is easier to use.
However, Razor is mostly used in MVC.
So how to use Razor in a non-MVC environment?
2.Use Razor in non-MVC Mode
With the open-source RazorEngine, we can use the Razor engine in non-asp.net mvc projects.
You can even use Razor in winform projects (you can write code generators with high flexibility ).
3.Workflow
Through a big discussion with Yang zhongke, I roughly got the Razor workflow, as shown in. Overview of this blog
Based on this figure.
Try to use
1. Import DLL
2. Create cshtml
Create a cshtml file in a non-mvc project (the cshtml file can be prompted automatically)
The method is simple. Create an html file and change it to XX. cshtml.
In this way, our preparations are complete! Start playing.
3.Write a loop in cshtml using c # syntax
In}, you can write C # code. C # code can be mixed with html code,
Writing like this can remind xiaobian of the years of doing php.
4.Read data from common processing programs
From the flowchart at the beginning, we know that we still need to use the Razor object to read the cshtml program.
Let him form an assembly and then generate html.
In fact, it is not very complicated to use it.
You can do this.
5) cshtmlHow to read values in an object
1) First, in a general processing program, an extra parameter is provided when the Parse method is called.
This parameter is the object you want to read in cshtml. (Theoretically, everything works)
2) Then we can find this object in cshtm.
@ Model. Age
@ Model. Name
You can write this code in cshtml and output it wherever you want.
End
So far, we have solved several basic problems about how to use the Razor template engine in a non-mvc environment.
1) how to create an environment. Import the dll to create a cshtml file.
2) embed C # code in the form. Effect of mixed editing
3) how to obtain the object Value in cshtml
This is basically the case.