【问题标题】:ASP.NET web forms equivalent of Razor's @{ }ASP.NET Web 表单等价于 Razor 的 @{ }
【发布时间】:2013-12-26 16:10:55
【问题描述】:

我的措辞不够准确,无法在 Google 上找到合适的结果。在 Razor 中,您可以使用以下标签在视图中嵌套 .NET 代码块(关键是多行使用):

@{
   ...
}

什么是等效的网络表单?

【问题讨论】:

  • 投反对票就跑是吧?

标签: asp.net razor webforms


【解决方案1】:

您可以将代码块嵌套在:<% ... %>

【讨论】:

    【解决方案2】:

    这是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>
    

    【讨论】:

      【解决方案3】:

      您可以联系我们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
      

      【讨论】:

      • &lt;%$ %&gt; 用于访问资源
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-12
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多