What is the difference between <% %> and <%=%>?

前端 未结 4 2327
庸人自扰
庸人自扰 2020-11-29 01:41

What is the difference between <% %> and <%= %> in ASP.NET MVC? And when to use which?

4条回答
  •  臣服心动
    2020-11-29 02:26

    See also this question. MVC hasn't changed how these bee-stings work, just how often they're used.

    Basically:

    • <% - execute code
    • <%@ - page directive
    • <%$ - resource access
    • <%= - explicit output to page
    • <%# - data binding
    • <%-- - server side comment block

    Also new in ASP.Net 4:

    • <%: - writes out to the page, but with HTML encoded

提交回复
热议问题