当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc - It seems the semicolon is sometimes optional in the WebForms View Engine

问题描述:

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 Response.Write(). The .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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: