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
    • 312
    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:

    <!-- Single statement block -->
    @{ var myMessage = "Himanshu Joshi"; }
    
    <!-- Inline expression or variable -->
    <p>The value of myMessage is: @myMessage</p>
    
    <!-- Multi-statement block -->
    @{
    var greeting = "Welcome to our site!";
    var weekDay = DateTime.Now.DayOfWeek;
    var greetingMessage = Hello + " Today is: " + weekDay;
    }
    <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:

    <html>
    <body>
    @RenderPage("Welcome.cshtml")
    <h1>This is my Web Pages</h1>
    @RenderPage("Index.cshtml")
    </body>
    </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
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: