我无法准确地说出这一点,以便在谷歌上找到合适的结果。在Razor中,您可以使用这些标记在视图中嵌套.NET代码块(关键是多行使用):
@{
...
}
什么是网络表单等价?
答案 0 :(得分:4)
<% %> 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
答案 1 :(得分:1)
这是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>
答案 2 :(得分:0)
您可以在<% ... %>