Tips to program in ASP.NET using Razor
Here we are going to learn about programming in asp.net using Razor syntax. Some tips to write the program are given below, will be helpful for beginners.
It is about how to add codes, variables and using literal strings in Razor.
Find Tips to program in ASP.NET using Razor
Use @ character before code block:
Before every Razor code block use the @ character
@{ var Number = 123; }
@{ var Literal_String = "Hello World"; }Use @ character before a variable:
You should use the @ character for the variables you use in the inline expression.<p>The value of number is: @Number</p>
<p>Your string is : @Literal_String</p>Enclose code blocks in braces:
As in the first example you should write code inside the curly braces@{
var Number = 123;
var Literal_String = "Hello World";
}
<p>Number and string: @Number and @Literal_String</p>Inside a block, you end each code statement with a semicolon:
As like asp.net the codes should be end with semicolon@{
var Number = 123;
var Literal_String = "Hello World";
}Inline expression don't need semicolon:
Code inside the HTML tags don't need any semicolon<p>The number is: @Number</p>
Use variables to store values:
We can store any datatype into a variable created using var keyword
@{ var Today_Date = DateTime.Now; }Razor Code is case sensitive:
Razor is case sensitive so the name's with small letters differ from capitals.@{
var Number = 12;
var number = 23;
}
in the above example both are different variablesStrings that contains a backslash, double quotation marks, uses a verbatim(@) symbol.
If you're using backslash(\) or double quotation marks in code block should be started with the @ character@{ var Folder_Name = @"C:\MyFolder\"; }
@{ var Using_Double_Quote = @"The person said: ""Hello, today is Monday."""; }Comments:
Razor uses @* for start of a command and *@ for end a command. It can be used for both single line and multiple line commands@* command example *@
That is good but not enough for study,,,,
can u plz elaborate this more