.NET “code nugget blocks”?

后端 未结 5 1890
鱼传尺愫
鱼传尺愫 2020-12-03 05:03

So in .NET we have...

<%=

<%: (new to .NET 4 - syntactic sugar for HTML encoding)

<%#

<%@

What exactly are these?

An

5条回答
  •  借酒劲吻你
    2020-12-03 06:01

    It is difficult to be clear and definitive about names because Microsoft is often not clear and definitive. For example I do not know what the name of <%: ... %> is.

    It is also difficult to be certain of what the current documentation is and Microsoft is working on solving that problem.

    The following table cross-references what is in Introduction to ASP.NET inline expressions in the .NET Framework with what is in ASP.NET Page Syntax.

        Syntax      | Support Article           | Docs
        <% ... %>     | Embedded Code Block       | inline code (see Code Render Blocks)
        <%= ... %>    | Inline Expression Block   | inline expression (see Code Render Blocks)
        <%@ ... %>    | Text Template Directive   | Text Template Directive
        <%# ... %>    | Data-Binding Expression   | Data-Binding Expression
        <%$ ... %>    | Expression Builder        | ???
        <%-- ... %>   | Server-Side Comments      | Server-Side Comments
        <%: ... %>    | N/A                       | N/A
    

    <% ... %>: Embedded Code Block

    The Embedded Code Block provides backward compatibility with classical ASP and is also used by PHP and JSP. Since they are embedded within HTML they tend to make HTML difficult to read and maintain.

    <%= ... %>: Inline Expression Block

    An Inline Expression Block is executed as if it is a parameter of a Response.Write(…) statement.

    <%: ... %>: ???

    The same as <%= Server.HtmlEncode(...) %> where ... is the parameter of Server.HtmlEncode.

    <%@ ... %>: Text Template Directive

    The Text Template Directive specifies settings used by the page and by user control compilers when they process ASP.NET Web Form (.aspx) pages and User Control (.ascx) files.

    <%# ... %>: Data-Binding Expression

    The Data-Binding Expression binds a server control property to a data source.

    <%$ ... %>: Expression Builder

    The Expression Builder sets the value of a control's property to the value in an application's configuration or resource file. An Expression Builder expression consists of:

    Expression Prefix: Expression Value
    

    Where the Expression Prefix is the kind of expression such as a node in the Web.config file and Expression Value is the name of a key in the node. The result is the value specified for the key.

    <%-- ... %>: Server-Side Comments Block

    The Server-Side Comments Block allows comments to be placed anywhere in HTML except in code blocks.

    Miscellaneous Syntax

    The following are also in the Microsoft Docs documentation page, in case that helps.

        Syntax                                      | Docs
               | Custom Server Control
                  | Server-Side Object Tag
         | Server-Side Include Directive
    
        

    提交回复
    热议问题