For content, things that are not easy to change, we want to give it a static, There is also a situation, such as the Sina Cloud does not support. NET, in order to be able to run our website, can only put some static pages above, plus JSONP to achieve interaction, we know. NET has a lot of template engine, but are not original, so basically there is no code hint, use up more uncomfortable, since razor out, chat also abandoned the original use Nvelocity, and the use of the original razor.
OK, let's see how to play first, let's go to CodePlex up and down two DLLs. http://razorengine.codeplex.com/
I would like to Razor grammar, everyone has been to the same, but I almost a year did not contact with MVC, but also forget about it, simply introduced some of the bar ~ ~ ~
In general, as long as the razor support four-like features, 80% of the function can be completed.
One: Simple placeholder replacements
Because it is too simple, it does not take effort to read from the cshtml file, instead of using a string instead.
How, simple placeholder replacement is not very simple, more semantically than those {0},{1} ~
Second: can realize the if,foreach and so on flow control statement
First look at how to play in the template, the most important thing is to have code hints, is completely familiar with the C # syntax
<! DOCTYPE html>
Then look at the background C # code
Class program
{
static void Main (string[] args)
{
string path1 = Environment.currentdirectory + "... /.. /.. /index.cshtml ";
var index = System.IO.File.ReadAllText (path1, encoding.getencoding ("GBK"));
var list = new List<student> ()
{
new Student () {name= "John"},
new Student () {name= "Dick"},
new Stude NT () {name= "Harry"},
};
var result = Razor.parse (index, new {studentlist = list});
}
public class Student
{public
string Name {get; set;}
}