【问题标题】:Hide ascx markup based on condition根据条件隐藏 ascx 标记
【发布时间】:2016-04-16 21:14:04
【问题描述】:

我在 ascx 中有一些小标记,例如这个简单的 a href,例如:

if (siteUrl) {
    <a href="<%= siteUrl %>"> <%= Message here %> </a> 
}
 // otherwise don't display Url and message

(如果文件后面的代码中的变量为空,我想隐藏它。) 显然上面的代码是一个尝试,需要调整以在 ascx 中工作。

有什么好的方法可以做到这一点?有没有办法例如将标记放在 ascx 中的某种占位符中并使其在条件下可见?语法提示赞赏。谢谢一堆。

【问题讨论】:

    标签: html asp.net ascx


    【解决方案1】:

    你使用&lt;% %&gt;的类似方式,只是不添加=,你的代码将是:

    <% if (!string.IsNullOrEmpty(siteUrl)) {%>
        <a href="<%= siteUrl %>"> <%= MessageMe %> </a> 
    <% }%>
    

    您也可以阅读Scott Guthrie block for that syntax

    【讨论】:

      猜你喜欢
      • 2016-10-29
      • 2021-05-28
      • 1970-01-01
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多