Application of Razor in WebApp frame

Source: Internet
Author: User

There are two chapters in front of the WEBAPP framework "WebApp MVC," "Not the same" lightweight Internet application Development Framework and "WEBAPP MVC Framework Development Details Induction", where the view engine is used nvelocity, recently found razor good, syntax comparison like C #, And it's easier to have tips in the VS IDE, and it's nice to have someone codeplex razor out of ASPX MVC from an independent open-source project Razorengine, and immediately study it and add it to the framework.

Razorengine Open Source website: http://razorengine.codeplex.com/

Let's look at an example of using the Razor view engine in the WebApp framework:

1. Simple example, Hello Worlod

2.Razor Method Instance

Using the keyword @helper to create a method AA, the output string Hello here and MVC in the razor syntax is a bit different, want to do not error to use @ () to include the input content, this place began not to know the old error, the last mode source only found that must be written.

3. Judging instances

4. Cycle instances

5. Methods Tourl and Loadjs

6. Include external files

7. Background TestController Code

[AOP (typeof(Headcomponent),typeof(footercomponent))]  Public voidRazortest01 () {List<string> data =Newlist<string>(); Data. ADD ("option 1"); Data. ADD ("Option 2"); Data. ADD ("option 3"); Viewdata.add ("Data", data); Viewdata.add ("name","Kakake"); ViewResult= Toview (@"views\test\test01.cshtml"); }

 Public classheadcomponent:abstractrazorcomponent { Public Override stringGetFilePath () {return "views/test/head.cshtml"; }         Public Override voidLoadviewdata () {Viewdata.add ("Head","This is the page header! "); }    }
  Public classfootercomponent:abstractrazorcomponent { Public Override stringGetFilePath () {return "views/test/footer.cshtml"; }         Public Override voidLoadviewdata () {Viewdata.add ("Footer","this is the footer! "); }    }

Interface effect:

Summary: Using razor does make our code look more comfortable, but razor may be a bit lacking in performance. Also, if you modify the cshtml file, you need to exit the service to recompile the project to run, or the execution may go wrong .

Application of Razor in WebApp frame

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.