Razor syntax

Performing same example with Razor syntax :-

13

@ layout = null;

Var num 1 = 0;

Var num 2 = 0;

Var Result = 0;

If (is post)

{

Num 1 = request [‘T1’].As Int [];

Num 2 = request [‘T2’].As Int [];

Result = num 1 + num2

}

Design :-

2In the first example we declare variable of int type and conversion is done by using Convert . to int 32 (); method

2This is completely in C # syntax. Here C# syntax with Razor syntax.

2In IInd Method we completely used Razor syntax that is Declaring the variable using keyword, and performing conversion using as int () method.

Interested in mastering ASP.net Training?

Enroll now for FREE demo on ASP.net Training.

Conversion Methods in Razor Syntax :-

As Int () :-              convert the data to integer type .

As Float () :-             convert the data to Float type

As Decimal () :-           convert the data to Decimal type.

As Date and time() :-  convert the data to  date time type

As Bool ()       :-             convert the data to  Bool type

To string ()     :-              convert the data to String type

Data type Comparison   Methods :-

  1. Is Int () 2compares the given data in integer type, return true. If the data belongs to integer type other vise return false.
  2. Is Float () 2compares the given data in F type, return true. If the data belongs to integer type other vise return false.
  3. Is Decimal () 2compares the given data in Decimal type, return true. If the data belongs to integer type other vise return false.
  4. Is Date time () 2compares the given data in Date time type, return true. If the data belongs to integer type other vise return false.
  5. Is Bool () 2compares the given data in Bool type, return true. If the data belongs to integer type other vise return false.

For indepth understanding click on