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