【发布时间】:2013-12-26 16:10:55
【问题描述】:
我的措辞不够准确,无法在 Google 上找到合适的结果。在 Razor 中,您可以使用以下标签在视图中嵌套 .NET 代码块(关键是多行使用):
@{
...
}
什么是等效的网络表单?
【问题讨论】:
-
投反对票就跑是吧?
我的措辞不够准确,无法在 Google 上找到合适的结果。在 Razor 中,您可以使用以下标签在视图中嵌套 .NET 代码块(关键是多行使用):
@{
...
}
什么是等效的网络表单?
【问题讨论】:
您可以将代码块嵌套在:<% ... %>
【讨论】:
这是example:
<body>
<form id="form1" runat="server">
<% for(int i = 0; i < 6; i++) %>
<% { Response.Write("<br>" + i.ToString()); }%>
</form>
</body>
还有一个例子:
<script runat=server>
protected String GetTime()
{
return DateTime.Now.ToString("t");
}
</script>
<html>
<body>
<form id="form1" runat="server">
Current server time is <% =GetTime()%>.
</form>
</body>
【讨论】:
您可以联系我们Embedded code blocks。
<% %> runs server-side code, like an if-else block, for loop, etc.
例如:
<% if(condition)
{
// Do something here
}
else
{
// Do something else here
}
%>
还有其他几种:
<%# %> is for data-binding expressions
<%= %> is the equivalent of `Response.Write()`
<%: %> is for HTML-encoding the data
<%@ %> is for directives, usually page directives in ASP.NET
【讨论】:
<%$ %> 用于访问资源