【问题标题】:What does the <#= symbol mean?<#= 符号是什么意思?
【发布时间】:2013-08-28 11:56:46
【问题描述】:

&lt;# 这个符号在 asp.net 中的含义 它在 html 标签内。

 <td><#= userInfo.observerResponseKey != null ? (userInfo.observerStatus == '<%= Enum.GetName(typeof(Status), Status.Draft) %>' ? "Draft shared " +  userInfo.observerDateSubmittedString : userInfo.observerStatus == '<%= Enum.GetName(typeof(Status), Status.Private) %>' ? "In Progress" :  "Completed " + userInfo.observerDateSubmittedString) + " by " + userInfo.observerName : "Not Started"  #></td>

如果结果是“进行中”或“完成”,我想将 img 添加到 td。

我尝试添加喜欢

 <td><#= userInfo.observerResponseKey != null ? (userInfo.observerStatus == '<%= Enum.GetName(typeof(Status), Status.Draft) %>' ? "Draft shared " +  userInfo.observerDateSubmittedString : userInfo.observerStatus == '<%= Enum.GetName(typeof(Status), Status.Private) %>' ? "In Progress" :  "Completed " + userInfo.observerDateSubmittedString) + " by " + userInfo.observerName #><img src="../../images/icon_delete_red.png" /> <#= : "Not Started"  #></td>

但它的抛出错误“Unparse Microtemplate”

那么,那个标签

请帮帮我..

【问题讨论】:

标签: asp.net server-tags


【解决方案1】:

嵌入式代码块。

<%# %> is for data-binding expressions

例如,在 ASP.NET GridView 中,很多时候你会看到这样的内容:

<%# Eval("DataColumnName") %>

还有其他几种:

<%= %> is the equivalent of `Response.Write()`
<% %> runs server-side code, like an if-else block
<%: %> is for HTML-encoding the data
<%@ %> is for directives, usually page directives in ASP.NET

【讨论】:

  • @MikeSmithDev - 是的,感谢您了解这一点。答案已更新。
【解决方案2】:

http://demos.telerik.com/aspnet-mvc/razor/grid/templatesclientside

Telerik 将这种语法用于代码模板

【讨论】:

    【解决方案3】:

    这是一个代码块或“代码块”。本质上,它允许您嵌入要由服务器处理和呈现的代码,然后再发送到客户端。

    看到这个.NET "code nugget blocks"?

    或

    What are these called in ASP.NET <%: %>?

    一个例子:

    <img id="<%= someValue.ToString() %>" src"http://website.com/someImg.jpg" />
    

    【讨论】:

    • 是的,当它由服务器呈现时,它作为纯 html 到达客户端,因此您可以使用 html 元素做任何您需要的事情。这只是一种将服务器端变量注入 html 的机制。
    • 但是怎么添加img标签呢?我应该在使用 img 标签之前关闭服务器标签,然后在 img 标签之后再次打开服务器标签吗?如果我这样做了,它的抛出错误
    • @Kokila 如果这回答了您的问题,请选择它作为正确答案。
    猜你喜欢
    • 2011-04-07
    • 2014-05-11
    • 1970-01-01
    • 2022-12-22
    • 2010-09-29
    • 2011-04-18
    • 1970-01-01
    • 2020-04-02
    • 2019-11-17
    相关资源
    最近更新 更多