---
title: "Explain different types of block statements in Razor view Engine?"  
description: "Explain different types of block statements in Razor view Engine?"  
author: "Anonymous User"  
published: 2020-02-04  
updated: 2020-02-04  
canonical: https://www.mindstick.com/forum/155782/explain-different-types-of-block-statements-in-razor-view-engine  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# Explain different types of block statements in Razor view Engine?

Please [briefly describe](https://www.mindstick.com/interview/22943/briefly-describe-android-application-architecture) different types of [block](https://www.mindstick.com/forum/157599/explain-the-process-control-block-pcb-in-the-operating-system) statements used in razor in MVC.

## Replies

### Reply by Nishi Tiwari

In razor view engine has a different type of block statements are available:-

- **Single Statement Block**
- **Multiple Statement Block**

## Single Statement Block and Inline Expression

We define code in opening and closing curly brackets @{...} and single statement block code will be like this

```
@{var Series = 4 ;}
@{var RazorMessage = "Hello Razor";}
<p> MVC series : @Series</p>

<p> Razor Message : @RazorMessage</p>

```

## Multiple Statement Block and Inline Expression

Here, in multiple statement block, we will define all variables in single curly brackets @{...} so we must need to end each variable with a semicolon and our multiple statement block code will be shown like below:-

```
 @{
    var Title = "Welcome to Razor syntax!";
    var weekDay = DateTime.Now.DayOfWeek;
    var HomeMessage = Title + " Today is: " + weekDay;
}

<p> Razor Message : @HomeMessage</p>
```

Usually, in **[razor engine code written at top of view will be accessible](https://www.mindstick.com/forum/155781/what-is-razor-view-engine-in-asp-dot-net-mvc)** in any other code block in same view page else in case if we will declare a variable in middle and try to access a top we will not be able to access those variables and it will throw an error as it shows:-

![Explain different types of block statements in Razor view Engine?](https://www.mindstick.com/mindstickforums/96bf1a34-3292-49aa-b164-caa48e59c7c8/images/05dfc707-1552-4b9c-a1a1-1e5661d6d9ea.png)

We observe in the above code we tried to access variable "i" before declaring that is the reason it throws an error as shown above.


---

Original Source: https://www.mindstick.com/forum/155782/explain-different-types-of-block-statements-in-razor-view-engine

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
