加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – <#=#>是什么意思

发布时间:2020-12-16 03:27:44 所属栏目:asp.Net 来源:网络整理
导读:阅读 Code Generation and T4 Text Templates,我发现这个语法#= DateTime.Now# htmlbody The date and time now is: #= DateTime.Now #/body/html 它与%= DateTime.Now%有什么不同?或%#DateTime.Now%. 谷歌搜索没有显示 解决方法 我不能声称自己熟悉T4
阅读 Code Generation and T4 Text Templates,我发现这个语法<#= DateTime.Now#>

<html><body>
 The date and time now is: <#= DateTime.Now #>
</body></html>

它与<%= DateTime.Now%>有什么不同?或<%#DateTime.Now%>.

谷歌搜索没有显示

解决方法

我不能声称自己熟悉T4文本模板,但看起来区别在于设计/构建时代码生成(可以包括可执行语句)和运行时代码执行.

所以<#=#>计算用于生成文件的模板中的表达式.

并且<%=%>执行块中的代码并将其写入输出流.这将在首次执行页面时进行JIT编译,但关键是它表示在页面运行时要执行的代码块,而不是在生成模板化文件期间执行.

第三种形式,<%#%>表示数据绑定表达式,也在页面执行时进行评估.

Expression control blocks

An expression control block evaluates an expression and converts it to
a string. This is inserted into the output file.

Expression control blocks are delimted by the symbols <#= … #>

For example,the following control block causes the output file to
contain “5”:

<#= 2 + 3 #>

资料来源:http://msdn.microsoft.com/en-us/library/bb126478

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读