Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor semicolon missing?

Tags:

syntax

razor

In one of my web MVC3 sites, I'm know seeing a semi-colon at bottom of the page. That being the case, I'm going back through my razor templates and getting more confused than before.

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

like image 532
B2K Avatar asked Mar 03 '14 20:03

B2K


People also ask

What type of error is a missing semicolon?

The JavaScript exception "missing ; before statement" occurs when there is a semicolon ( ; ) missing somewhere and can't be added by automatic semicolon insertion (ASI). You need to provide a semicolon, so that JavaScript can parse the source code correctly.

What is Razor syntax in C#?

Razor syntax is a simple programming syntax for embedding server-based code in a web page. In a web page that uses the Razor syntax, there are two kinds of content: client content and server code.

Does MVC use Razor?

Razor is one of the view engines supported in ASP.NET MVC. Razor allows you to write a mix of HTML and server-side code using C# or Visual Basic.

What is Razor code blocks?

Razor code blocksUse this approach to render HTML that isn't surrounded by an HTML tag. Without an HTML or Razor tag, a Razor runtime error occurs. The <text> tag is useful to control whitespace when rendering content: Only the content between the <text> tag is rendered.


1 Answers

In Razor syntax 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.";
}

  1. Inline expressions don't end with a semicolon.
<!-- Inline expression, so no semicolon -->
<p>Today's weather: @weatherMessage</p>

These rules are outlined here.

like image 126
Ed Guiness Avatar answered Oct 14 '22 04:10

Ed Guiness