dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersbaskar
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » .NET programming » ASP.NET/Web Applications

Tips to program in ASP.NET using Razor


Posted Date:     Category: ASP.NET/Web Applications    
Author: Member Level: Gold    Points: 10


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 variables

Strings 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 *@





Did you like this resource? Share it with your friends and show your love!


Responses to "Tips to program in ASP.NET using Razor"
Guest Author: Naresh Kumar     31 May 2012
That is good but not enough for study,,,,
can u plz elaborate this more



Guest Author: Hanum     11 Jun 2012
Hi, If you are talking about sacreh in your own website then you must be ensured that the keywords u r putting in database, if yes then use a select command query and it is displayed result.


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Secure your web.config by encryption
    Previous Resource: Trend line for Line chart in SSRS 2005
    Return to Resources
    Post New Resource
    Category: ASP.NET/Web Applications


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Razor syntax  .  Asp.net razor programming  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.