有没有办法在 HTML 尖括号内嵌套(或转义)ASP.NET 内联代码?

发布于 2024-07-26 05:46:18 字数 352 浏览 2 评论 0原文

是否可以在 ASP.NET 中执行类似以下操作:

<tr<%= index++ % 2 == 0 ? " class=\"alt-row\"" : ""; %>>

换句话说,是否有办法转义内联代码块或其他内容的尖括号?

(我知道替代方法是:

<% if (index++ % 2 == 0) { %>
    <tr class="alt-row">
<% } else { %>
    <tr>
<% } %>

。我只是好奇另一种方式是否可能)

is it possible to do something like the following in ASP.NET:

<tr<%= index++ % 2 == 0 ? " class=\"alt-row\"" : ""; %>>

in other words, is there a way to escape the angle brackets for the inline code block or something?

(i know the alternative is:

<% if (index++ % 2 == 0) { %>
    <tr class="alt-row">
<% } else { %>
    <tr>
<% } %>

. i'm just curious if the other way is possible)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猥琐帝 2024-08-02 05:46:18

是的,您可以这样做(至少在 MVC 中),尽管您的示例有一些错误。

这是一个固定版本:

<tr<%= index++ % 2 == 0 ? " class=\"alt-row\"" : "" %>>

Yes, you can do this (at least, in MVC), though your example has a couple errors.

Here's a fixed version:

<tr<%= index++ % 2 == 0 ? " class=\"alt-row\"" : "" %>>
滥情稳全场 2024-08-02 05:46:18

你试过了吗? 类似的测试对我来说效果很好。

Have you tried it yet? A similar test worked just fine for me.

南街九尾狐 2024-08-02 05:46:18

我用过<% %>; 构造内部标签来分配属性,所以我想这会起作用。 没效果吗?

I've used the <% %> construct inside tags to assign properties so I would imagine this would work. Did it not work?

我偏爱纯白色 2024-08-02 05:46:18

尝试这个。

 <tr class="<%= index++ % 2 == 0 ? "alt-row" : "" %>">

Try this.

 <tr class="<%= index++ % 2 == 0 ? "alt-row" : "" %>">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文