Abandon nvelocity, come and play razor

Source: Internet
Author: User

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;}  
    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.