


Share ASP.NET study notes (13) Detailed explanation of Razor syntax
ASP.NET Razor - C# and VB code syntax
Razor supports both C# (C sharp) and VB (Visual Basic).
Main Razor C# syntax rules
Razor code blocks are enclosed in @{...}
Inline expressions (variables and functions) begin with @
Code statements end with semicolons
Variables are declared using the var keyword
Strings are enclosed in quotes
C#Code is case sensitive
The extension of C# files is .cshtml
C# examples
1 |
|
Main Razor VB syntax rules
Razor code blocks are contained in @Code…
Inline expressions (variables and functions) in the end code begin with @
Variables are declared using the Dim keyword
Strings are enclosed in quotes
VB code is not case sensitive
The extension of VB files is .vbhtml
Example
1 |
|
How does it work?
Razor is a simple programming syntax for embedding server code in web pages.
Razor syntax is based on the ASP.NET Framework, a part of the Microsoft.NET framework specifically designed for creating web applications.
Razor syntax supports all ASP.NET features, but uses a simplified syntax that is easier to learn for beginners and more efficient for experts.
A Razor web page can be described as an HTML web page with two types of content: HTML content and Razor code.
When the server reads the page, it first runs the Razor code before sending the HTML page to the browser. Code executed on the server can perform tasks that cannot be completed on the browser, such as accessing the server database. Server code can create dynamic HTML content and send it to the browser. From a browser perspective, the HTML generated by the server code is no different from the static HTML content.
Razor syntax ASP.NET web pages have special file extensions cshtml (Razor C#) or vbhtml (Razor VB).
Using Objects
Server coding often involves objects.
The "Date" object is a typical built-in ASP.NET object, but the object can also be customized, a web page, a text box, a file, a database record, etc.
Object Useful A database record might have a "save" method, an image object might have a "rotate" method, an email object might have a "send" method, and so on.
Objects also have attributes used to describe their respective characteristics. A database record may have FirstName and LastName properties.
ASP.NET date objects have a now property (written as Date.Now), and the now property has a day property (written as Date.Now.Day). The following example demonstrates how to access some properties of the data object:
Example
1 |
|
If and ElseCondition
An important part of dynamic web pages The thing is, you can decide what to do based on the conditions.
A common way to do this is to use an if ... else statement:
Example
1 |
|
读取用户输入
动态网页的另一个重要特点是,您可以读取用户输入。
输入是通过请求[]功能读取的,并且传送输入数据是经过IsPost条件判断的:
实例
1 |
|
【相关推荐】
2. 分享ASP.NET学习笔记(1)--WebPages Razor
3. 分享ASP.NET学习笔记(2)--WebPages 介绍
4. 分享ASP.NET学习笔记(3)WebPages 布局
6. 分享ASP.NET学习笔记(5)全局页面 AppStart 和 PageStart
The above is the detailed content of Share ASP.NET study notes (13) Detailed explanation of Razor syntax. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When it comes to API development, you may think of DjangoRESTFramework, Flask, and FastAPI. Yes, they can be used to write APIs. However, the framework shared today allows you to convert existing functions into APIs faster. It is Sanic . Introduction to Sanic Sanic[1] is a Python3.7+ web server and web framework designed to improve performance. It allows the use of the async/await syntax added in Python 3.5, which can effectively avoid blocking and improve response speed. Sanic is committed to providing a simple and fast way to create and launch

With the release of PHP 8.0, a new type alias syntax has been added, making it easier to use custom types. In this article, we'll take a closer look at this new syntax and its impact on developers. What is a type alias? In PHP, a type alias is essentially a variable that references the name of another type. This variable can be used like any other type and declared anywhere in the code. The main function of this syntax is to define custom aliases for commonly used types, making the code easier to read and understand.

Lambda expression is an anonymous function without a name, and its syntax is: (parameter_list)->expression. They feature anonymity, diversity, currying, and closure. In practical applications, Lambda expressions can be used to define functions concisely, such as the summation function sum_lambda=lambdax,y:x+y, and apply the map() function to the list to perform the summation operation.

The connection and difference between Go language and JS Go language (also known as Golang) and JavaScript (JS) are currently popular programming languages. They are related in some aspects and have obvious differences in other aspects. This article will explore the connections and differences between the Go language and JavaScript, and provide specific code examples to help readers better understand these two programming languages. Connection: Both Go language and JavaScript are cross-platform and can run on different operating systems.

PHP is a server-side scripting language widely used in Web development, and PHP8.0 version introduces a new parent class calling syntax to make object-oriented programming more convenient and concise. In PHP, we can create a parent class and one or more subclasses through inheritance. Subclasses can inherit the properties and methods of the parent class, and can modify or extend their functionality by overriding the methods of the parent class. In ordinary PHP inheritance, if we want to call the method of the parent class in the subclass, we need to use the parent keyword to refer to the parent

To master basic CSS selector syntax, specific code examples are required. CSS selectors are a very important part of front-end development. They can be used to select and modify various elements of HTML documents. Mastering basic CSS selector syntax is crucial to writing efficient stylesheets. This article will introduce some common CSS selectors and corresponding code examples. Element selector The element selector is the most basic selector, which can select the corresponding element by its tag name. For example, to select all paragraphs (p elements), you can use

Introduction to the syntax and usage of power operation in C language: In C language, power operation (poweroperation) is a common mathematical operation, which is used to calculate the power of a number. In C language, we can use standard library functions or custom functions to implement exponentiation operations. This article will introduce the syntax and usage of exponentiation operation in C language in detail, and provide specific code examples. 1. Use the pow() function in math.h. In C language, the pow() function is provided in the math.h standard library for executing

The C programming language C is a general-purpose, high-level language originally developed by Dennis M. Ritchie at Bell Labs to develop the UNIX operating system. C was first implemented in 1972 on the DECPDP-11 computer. In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard. The UNIX operating system, C compiler, and almost all UNIX applications are written in C. For various reasons, C language has now become a widely used professional language. It is a structured language that is easy to learn, it produces efficient programs, it can handle low-level activities, and it can run on a variety of computers.
