PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 13, 2022

[FIXED] When is the semicolon required in Razor syntax?

 December 13, 2022     .net, asp.net-mvc, razor, syntax     No comments   

Issue

In one of my web MVC3 sites, I'm seeing a semicolon at the bottom of the page.

Are semicolons required on @using some.Library.Namespace; statements?


Solution

There are two rules for semicolons:

  1. Inside a code block, each complete code statement must end with a semicolon.

    <!-- Single-statement block -->
    @{ var theMonth = DateTime.Now.Month; }
    
    <!-- Multi-statement block -->
    @{
        var outsideTemp = 79;
        var weatherMessage = "Hello, it is " + outsideTemp + " degrees.";
    }
    
  2. Inline expressions don't end with a semicolon.

    <!-- Inline expression, so no semicolon -->
    <p>Today's weather: @weatherMessage</p>
    

Further Reading

  • Introduction to Using the Razor Syntax
  • Razor Syntax Reference


Answered By - Ed Guiness
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing