Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Razor in .NET

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 368
    Comment on it

    Razor is a syntax which add server-based code to web pages. Razor engine in .NET is used in place of ASP engine for running applications.

     

    The page contains ordinary HTML markup, with one addition the @marked Razor code.

    See the example below:

    1. <!-- Single statement block -->
    2. @{ var myMessage = "Himanshu Joshi"; }
    3.  
    4. <!-- Inline expression or variable -->
    5. <p>The value of myMessage is: @myMessage</p>
    6.  
    7. <!-- Multi-statement block -->
    8. @{
    9. var greeting = "Welcome to our site!";
    10. var weekDay = DateTime.Now.DayOfWeek;
    11. var greetingMessage = Hello + " Today is: " + weekDay;
    12. }
    13. <p>The greeting is: @greetingMessage</p>

     

    Output of above code will be:

    The value of myMessage is: Himanshu Joshi

    The greeting is: Hello  Today is  Monday

     

    With Web Pages you can use the @RenderPage() method to import content from separate files.

    See the example below:

    1. <html>
    2. <body>
    3. @RenderPage("Welcome.cshtml")
    4. <h1>This is my Web Pages</h1>
    5. @RenderPage("Index.cshtml")
    6. </body>
    7. </html>

     

    The output of above code will be:

    This is a header from a separate file

    This is my Web Pages

    This is a paragraph

    This is a footer from a separate file

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: