Experience Razor features in ASP. net mvc 3

Source: Internet
Author: User

1. Gossip ASP. net mvc 3 beta

Without knowing it, MVC3 has been updated several times... This is because I have been developing Silverlight and have not paid much attention to ASP. net mvc. I read some articles in the garden before I made a preview.

However, I always think that dependency injection has long been a set, and the global interceptor is the same .. It seems that the development efficiency has not been greatly improved... (For your own opinion, I am currently learning the DI of MVC3BEAT ).

Except RAZOR...

Okay. Start now!

2. Commencement

2.1 directory

In _ ViewStart. cshtml, specify

StartPage. Layout will pre-load the page when the program starts.

 
 
  1. @{  
  2.     Layout = "~/Views/Shared/_Layout.cshtml";  

2.2 Implementation Framework page

_ Layout. cshtml

 
 
  1. <! DOCTYPE html>
  2. <Html>
  3. <Head>
  4. <Title> @ View. Title </title>
  5. <Link href = "@ Url. Content ("~ /Content/Site.css ")" rel = "stylesheet" type = "text/css"/>
  6. </Head>
  7. <Body>
  8. @ * Template page *@
  9. <Div>
  10. <Fieldset>
  11. <Legend> Main </legend>
  12. @ RenderBody ()
  13. </Fieldset>
  14. <Fieldset>
  15. <Legend> bottom footer </legend>
  16. @ RenderSection ("footer ");
  17. </Fieldset>
  18. </Div>
  19. </Body>
  20. </Html>

@ RenderBody () indicates the subject.

@ RenderSection ("footer"); rendering part: Copyright at the bottom.

In Index. cshtml

 
 
  1.  @section footer{   
  2. copyrght@@facingwaller  

2.3 display the variables in the view and the variables in the control.

Display

Display Controller

Definition in control:

 

Display in view

 

2.4 others

VIEW

 
 
  1. <Fieldset>
  2. Use view variable: @ variable = @ variable
  3. <Br/>
  4. Use Controller variable: @ View. variable from the Controller
  5. <Br/>
  6. Nested HTML Loops and Nested HTML Sample
  7. @ Foreach (var p in words ){
  8. <Big> @ p... </big>
  9. }
  10. <Br/>
  11. Use if else
  12. @ If (IsTrue ){
  13. <B> @ IsTrue is @ IsTrue </B>
  14. } Else {
  15. <B> @ IsTrue is @ IsTrue </B>
  16. }
  17. <Br/>
  18. Multi-line code
  19. @{
  20. Var number = 1;
  21. Var num2 = 2;
  22. }
  23. Multi-Token Statements variable and string patchwork statement @ (number + "number is" + number );
  24. <Br/>
  25. HTML Encoding
  26. <Br/>
  27. @ * Do not understand the following-Hope you can advise *@
  28. @ If (true ){
  29. <Text>
  30. Hi it's razor <br/>
  31. Follow me! I'm facingwaller
  32. </Text>
  33. <Br/>
  34. <Span> hi it's razor <br/>
  35. Follow me! I'm facingwaller </span>
  36. } Else {
  37.  
  38. }
  39. <Br/>
  40. Declarative HTML Helpers declaration help Method
  41. @ Helper WordInText (string text ){
  42. Foreach (var p in text ){
  43. <Li> @ p </li>
  44. }
  45. }
  46. Call @ WordInText ("ender ")
  47. </Fieldset>

Final Effect

3 exciting RAZOR

The RAZOR page engine is quite good.

1 replace the damn <%> with @. Obviously <, %,> is a very difficult key.

2. The @ + variable method for a single row is more concise.

3. provides a large number of static helper methods.

4. Its Chart and grid auxiliary methods make it easier to generate charts and tables to be more user-friendly than the previous contrib open source table Production Class Library.

WebImage helps you create images, including basic image operations. In the future, I will continue to experience and compare these ideas and share them with you...

4. Welcome to discuss other page engines.

There is something to say. At present, I have not seen the source code of RAZOR and have never experienced other (except webpages) page engines.

If this is not the case, please help us out. You are also welcome to talk about other page engines, especially ease of use, design ideas, development efficiency and performance.

Click here to download the relevant source code

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.