0% found this document useful (0 votes)
58 views

Razor Syntax: Click To Edit Master Title Style

Razor is a view engine for ASP.NET MVC that allows mixing HTML markup with C# or VB code using the .cshtml or .vbhtml file extensions. Razor syntax is compact and easy to learn as it uses familiar C#/VB syntax. Server-side code is denoted with @ and can be inline expressions without semicolons or multi-line blocks enclosed in braces. Text blocks, if/else conditions, and for loops can also be written in Razor syntax to generate dynamic HTML content from server-side code.

Uploaded by

Fahad Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Razor Syntax: Click To Edit Master Title Style

Razor is a view engine for ASP.NET MVC that allows mixing HTML markup with C# or VB code using the .cshtml or .vbhtml file extensions. Razor syntax is compact and easy to learn as it uses familiar C#/VB syntax. Server-side code is denoted with @ and can be inline expressions without semicolons or multi-line blocks enclosed in braces. Text blocks, if/else conditions, and for loops can also be written in Razor syntax to generate dynamic HTML content from server-side code.

Uploaded by

Fahad Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Click to edit Master title style

Razor Syntax
Instructor: Samra Shahzadi

1
Click to
Razor edit Master title style
Syntax

Razor is one of the view engines supported in ASP.NET MVC. Razor


allows you to write a mix of HTML and server-side code using C# or
Visual Basic. Razor view with visual basic syntax has .vbhtml file
extension and C# syntax has .cshtml file extension.

Razor syntax has the following Characteristics:


• Compact: Razor syntax is compact, enabling you to minimize the
number of characters and keystrokes required to write code.
• Easy to Learn: Razor syntax is easy to learn where you can use
your familiar language C# or Visual Basic.
• Intelligence: Razor syntax supports statement completion within
Visual Studio.

2 2
Click to
Inline edit Master title style
Expression

• Start with @ symbol to write server-side C# or VB code


with HTML code.
• For example, write @Variable_Name to display the value
of a server-side variable, e.g.,
• DateTime.Now returns the current date and time. So,
write @DateTime.Now to display the current date and
time, as shown below.
• A single line expression does not require a semicolon at
the end of the expression.

3 3
Click to
Inline edit Master
Expression title style
Example

4 4
Click to edit Master
Multi-statement Codetitle style
block

• You can write multiple lines of server-side code enclosed in braces


@{ ... }. Each line must ends with a semicolon the same as C#.

5 5
Click to Text
Display edit Master titleBlock
from Code style

• Use @: or <text>/<text> to display texts within code block.

6 6
Click to edit Master title style
Cont…

• Display text using <text> within a code block, as shown below.

7 7
Click tocondition
if-else edit Master title style

• Write if-else condition starting with @ symbol. The if-else code


block must be enclosed in braces { }, even for a single
statement.

8 8
Click
for to edit Master title style
loop

9 9
Click to edit Master title style
Model

• Use @model to use


model object anywhere in
the view.

1010
Click to edit Master title style

Thank You 

11

You might also like