如果有一个打开的 `<table>` 标签,Razor `if` 不会注册关闭 `}`? [英] Razor `if` does not register closing `}` if there is an opened `<table>` tag?

查看:11
本文介绍了如果有一个打开的 `<table>` 标签,Razor `if` 不会注册关闭 `}`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码,在 Razor 视图中:

This code, in a Razor view:

if (true)
{
    <table>
        <tbody>
}

...

if (true)
{
        </tbody>
    </table>
}

不运行.它声称在第一个 if() 语句上没有结束 },我猜这是因为

标签.

does not run. It claims that there is no closing } on the first if() statement, and I'm guessing it's because of the <table> tag.

有没有办法解决这个问题来有条件地插入我的

标签?

Is there a way I can work around this to conditionally insert my <table> tags?

推荐答案

尝试在标签前加上 @::

if (true)
{
    @:<table>
        @:<tbody>
}

...

if (true)
{
        @:</tbody>
    @:</table>
}

这篇关于如果有一个打开的 `&lt;table&gt;` 标签,Razor `if` 不会注册关闭 `}`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆