Razor view engine, how to write inbetween html?

2019-04-04 16:29发布

i have some problem with a razor syntax. I would like to know how to write inbetween html.. see this sample..

<ul>
    @foreach (var x in Model) {
        <li>
            @x.Subject - Tags:&nbsp;

            @if (x.Tags != null)
            {

                foreach (var t in x.Tags)
                {
                    @t.Name
                }
            }
            else
            { 
                No tags
            }
        </li>
    }
</ul>

I should be able to write "No Tags" but this doesnt work... No tags seem included in the code (which is not what i want.

Thanks

2条回答
神经病院院长
2楼-- · 2019-04-04 17:10

Does using the <text> tag work? For example:

<text>No tags</text>
查看更多
ゆ 、 Hurt°
3楼-- · 2019-04-04 17:15

You need to explicitly tell Razor that you're writing HTML, by writing @:No Tags or <text>No Tags</text>.

查看更多
登录 后发表回答