• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Working with Razor syntax

Working with Razor syntax

First Install asp.net mvc3 software

Creating a new mvc application using Razor view engine.

Go to vstd.net

    ↓

Click on file

    ↓

Click on new

    ↓

Click on project

    ↓

Select asp.net.mvc 3 web application

    ↓

Type application name

    ↓

Click on ok

Select the project template as internet application

Select the view engine as Razor

Click on ok

 

2When we create Razor application there do not we any deference

2Only deference is with in the view all view pages are created . CSHTML extension . where very view page will contain plain HTML code.

2So that Rendering will be much more minimized reduced.

 

–.Razor syntax will take 3 techniques to write

  1. Single line blocks
  2. Multi line blocks
  3. Inline Expressions

 

2in general syntax of Razor is for single line blocks

Syntax:

@  {statement 1 ;}

@  {statement 2 ;}

 

 

EX :-  1. @ {var  a = 10;}

@ {var  b = 20.5}

@  {var c = ‘satya’}

  1. @ {var a = 10;}

@ {double b = 20.5}

@   {String c = ‘satya’}

 

2We use the following syntax for multiple blocks

Syntax:

@ {  statement 1 ;}

statement 2;

}

Ex :-

  1. @ { var  a = 10;

Var   b = 20.5;

Var c = ‘satya’

}

  1. @ {var a = 10;}

@ {double b = 20.5}

@   {String c = ‘satya’}

 

Example  with Razor syntax:-

 

2Go to solution explorer

       ↓

Select Home folder

       ↓

Click with RM button

       ↓

Click on Add

       ↓

Click on view

       ↓

Type the view name as (Sample)

       ↓

De active check box use  view  (or) Layout

       ↓

Click on add

       ↓

A new view page is created with the name sample. HTML

       ↓

Go to source

       ↓

Write the following code.  On the top of page

@ { layout = null; }

@ {

Var a =10;

Var b = “satya”;

Var c = “20.5”

}

<body>

<h2> satya technologies </h2>

<div>

<p> value of a a is :-  @ a </p>

<p> value of a b is :-  @ b </p>

<p> value of a c is :-  @ c </p>

</div>

</body>

Learn ASP.net by Tekslate - Fastest growing sector in the industry.
Explore Online ASP.net Training and course is aligned with industry needs & developed by industry veterans.
Tekslate will turn you into ASP.net Expert.

Go to Home controller . cs  crate a action method name as sample

Public action result sample ()
{
Return view ();
}
Go to global .aspx
       ↓
Change the action name as sample and check and run the application
--> Create a new view page  (Sample)
       ↓
Write the following code for Razor syntax and design
@ { layout = null;
Int num 1, num2 , result = 0;
If  (is post)
{
Num 1 = convert to int 32 (Request [“T1”]);
Num 2 = convert to int 32 (Request [“T2”]);
Result = num 1 + num2;
<form .action = “”Method = “post”>
Enter first number
<input type = ‘text’@ “T1”/> <Br>
Enter Second number
<input type = ‘text’@ “T2”/> <Br>
Result is : @ Result
<input type = ‘submit’ id = “B1” value = “Add”/>
</form>

For indepth understanding click on

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Working with Razor syntax"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.