Why do I need a semicolon to end a
<% Html.BeginForm(); %>
but not need a semicolon when ending a
<%= Html.TextBox("Name") %>
Your first example is calling an Html extension method, which has the side effect of writing out content.
Your second example is using
=, which is short-hand for
.TextBox() does NOT have the side effect of writing into the Response, so you have to do it manually with the
Code blocks can have many lines of code, so the semicolons are needed.
<% Html.BeginForm(); DoSomeThingElse(); %>
When you use
<%= %> you are evaluating a single statement and outputting the result.