在MVC中,何时使用和?

时间:2022-07-26 21:04:30

In asp.net mvc, when do we use:

在asp.net mvc中,我们何时使用:

and

Do we ever need to put a ; (colon) ?

我们是否需要放一个; (冒号)?

3 个解决方案

#1


10  

<%= %> renders the output (string) of the contained command to the response. <% %> wraps executable statements (logic) in the view to control what gets executed. You don't use semicolons in the <%= %> blocks, but may in the <% %> depending on what statements are included.

<%=%>将包含的命令的输出(字符串)呈现给响应。 <%%>在视图中包装可执行语句(逻辑)以控制执行的内容。您不在<%=%>块中使用分号,但可以在<%%>中使用分号,具体取决于包含的语句。

String rendering:

字符串渲染:

<%= Html.Encode( Model. Property ) %>

<%= Html.Encode(Model.Property)%>

Code block:

代码块:

<% Html.RenderPartial( "ViewName" ); %>

<%Html.RenderPartial(“ViewName”); %>

EDIT: Here's a link to the reference.

编辑:这是参考的链接。

#2


4  

<%="something" %> is just a shortcut for Response.Write("something")

<%=“某事”%>只是Response.Write(“something”)的快捷方式

#3


0  

is used when you are calling some HtmlHelper method which returns a string e.g.: is used when you are calling some HtmlHelper method which is void:

#1


10  

<%= %> renders the output (string) of the contained command to the response. <% %> wraps executable statements (logic) in the view to control what gets executed. You don't use semicolons in the <%= %> blocks, but may in the <% %> depending on what statements are included.

<%=%>将包含的命令的输出(字符串)呈现给响应。 <%%>在视图中包装可执行语句(逻辑)以控制执行的内容。您不在<%=%>块中使用分号,但可以在<%%>中使用分号,具体取决于包含的语句。

String rendering:

字符串渲染:

<%= Html.Encode( Model. Property ) %>

<%= Html.Encode(Model.Property)%>

Code block:

代码块:

<% Html.RenderPartial( "ViewName" ); %>

<%Html.RenderPartial(“ViewName”); %>

EDIT: Here's a link to the reference.

编辑:这是参考的链接。

#2


4  

<%="something" %> is just a shortcut for Response.Write("something")

<%=“某事”%>只是Response.Write(“something”)的快捷方式

#3


0  

is used when you are calling some HtmlHelper method which returns a string e.g.: is used when you are calling some HtmlHelper method which is void: