Share the ASP. NET Learning Notes (1)--webpages Razor

Source: Internet
Author: User
Tags what is asp
in this tutorial, we will use the Razor markup for C # and Visual Basic code.

What is Razor?

Razor is a markup syntax that adds server-based code to a Web page

Razor features traditional ASP. NET markup, but easier to use and easier to learn

Razor is a server-side markup syntax that is similar to ASP and PHP

Razor support for C # and Visual Basic programming languages

Add Razor Code

Keep in mind the pages in the previous chapter instance:

<! DOCTYPE html>

Now add some Razor code to the instance:

Instance

<! DOCTYPE html>

The page contains normal HTML markup, and in addition to this, an @ ID Razor code is added.

The Razor code can perform many actions in real time on the server and display the results. (You can specify formatting options, otherwise only the default items are displayed.) )

The main Razor C # syntax rules

Razor code block included in @{...}

inline expressions (variables and functions) begin with @

The code statement ends with a semicolon

Variables declared with the VAR keyword

The string is enclosed in quotation marks.

C # code is case-sensitive

C # files have the. cshtml extension.

C # instances

<!--single statement block-->@{var mymessage = "Hello World";} <!--Inline expression or variable--><p>the value of Mymessage is: @myMessage </p> <!--multi-stateme NT Block-->@{var greeting = "Welcome to our site!"; var WeekDay = Datetime.now.dayofweek;var GreetingMessage = greeting + "Today is:" + WeekDay;} <p>the greeting is: @greetingMessage </p>

The main Razor VB grammar rules

The Razor code block is included in the @Code ... End Code in

inline expressions (variables and functions) begin with @

Variables declared with the DIM keyword

The string is enclosed in quotation marks.

VB code is case insensitive

The VB file extension is. vbhtml

Instance

<!--single statement block-to @Code Dim mymessage = "Hello World" End code<!--Inline expression or variable-- > <p>the value of mymessage is: @myMessage </p> <!--multi-statement block-to-@Codedim greeting = "We Lcome to our site! "Dim WeekDay = DateTime.Now.DayOfWeek Dim GreetingMessage = Greeting &" Today is: "& Weekdaye nd Code <p>the greeting is: @greetingMessage </p>

"Recommended"

1. ASP. NET free Video Tutorials

2. Share the ASP.--webpages Introduction

4. What is ASP. NET MVC? Summarizing ASP. NET MVC

5. Learn more about the difference between ASP. NET MVC and WebForm

Related Article

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.