Showing posts with label Razor View Engine Tutorial. Show all posts
Showing posts with label Razor View Engine Tutorial. Show all posts

Friday, 8 November 2013

Variable declaration in Razor in MVC


Variable declaration in Razor in MVC

As I discussed in my last article that Razor is the combination of HTML and C#, so we can use almost all programming feature in Razor.

In this article I am showing how we can work with variables.

In Razor we start programming code using @.

For Example:-

Create controller name Home and view Index

In this example I declared variable and calculate sum and print it.

Code of Index View

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
  
   
   @{
      
       int num1 = 10, num2 = 20;
       int num3 = num1 + num2;
      
    }

    The sum of @num1 and @num2 is @num3

</body>
</html>

As you can see that I declared block using @ and inside this block I have declared variable and perform some calculation. After that closing the block I used these variables.

Thursday, 7 November 2013

Razor View Engine in MVC

Razor View Engine

View engine plays a very important role as they are used to render HTML Page. We use Razor to create view in MVC. Razor View Engine is the combination of both HTML and Programming language. When we use C# programming language then its extension is .cshtml and when we use vb language then its extension is .vbhtml.

In asp.net Web Form application we use ASPX View Engine. In MVC we can work with both Razor and Web Form View Engine (Aspx View Engine). Razor is the default view engine of MVC.

In this tutorial Series I will try to discuss each point of Razor.

Note: - Kindly go through View in MVC