May 12, 2021 ASP.NET
1. ASP.NET Razor - C# and VB code syntax
2. The main Razor C# syntax rule
Razor supports both C sharp and VB (Visual Basic).
This section explains the syntax rules for Razor C# and Razor VB.
Razor is a simple programming syntax that embeds server code in a Web page.
The Razor syntax is based ASP.NET framework, and is designed to create parts of the web application Microsoft.NET framework.
Razor syntax supports all ASP.NET features, but uses a simplified syntax that is easier for beginners to learn and more efficient for experts.
Razor pages can be described as HTML pages with two types of content: HTML content and Razor code.
When the server reads the page, it first runs razor code and then sends the HTML page to the browser. C ode executed on the server can perform tasks that cannot be accomplished on a browser, such as accessing the server database. S erver code creates dynamic HTML content that is then sent to the browser. From a browser point of view, the HTML generated by the server code is no different from static HTML content.
The ASP.NET page with Razor syntax has a special file extension, cshtml (Razor C#) or vbhtml (Razor VB).
Server encoding 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, and so on.
The object has a method for execution. A
database record may have a "Save" method, an image object may have a "Rotate" method, an e-mail object may have a "Send" method, and so on.
Objects also have properties that describe their characteristics.
A database record may have FirstName and LastName properties.
ASP.NET date object has a Now property (written as Date.Now) and the Now property has a Day property (written date.Now.Day). T
he following example shows how to access some properties of a Data object:
An important feature of dynamic web pages is that you can decide what to do based on your criteria.
A common way to do this is to use if ... Else statement:
Another important feature of dynamic web pages is that you can read user input.
The input is read through the Request?function, and the transfer of input data is determined by the IsPost condition: