【发布时间】:2018-05-12 16:59:42
【问题描述】:
我正在迭代模型的 cmets(Comment 对象的集合),并且需要根据属性 Private 是 true 还是 false 来设置它们的样式。
我尝试基于这样的属性添加一个类:
<div class="contact-card comment_p_@(comment.Private)">
但是生成的html一直给我
<div class="contact-card comment_p_class">
即使我在这个元素的正下方
<p>@comment.Private</p>
根据需要输出<p>True</p> 或<p>False</p>。
这是完整的循环:
@foreach (var comment in comments)
{
<div class="contact-card comment_p_@comment.Private">
<strong>@comment.UserName</strong>
<p>@comment.Private</p>
<strong class="pull-right">@comment.DateTime</strong>
<p style="white-space: pre-wrap;">@comment.Content</p>
</div>
}
以及一次迭代的输出:
<div class="contact-card comment_p_class">
<strong>skotze</strong>
<p>True</p>
<strong class="pull-right">29/11/2017 03:18:12</strong>
<p style="white-space: pre-wrap;">asda123</p>
</div>
我也试过了
<div class="contact-card comment_p_@comment.Private">
<div class="@comment.Private">
<div class="comment-@comment.Private">
但我总是得到相同的结果...当我尝试使用该属性设置类时,输出 html 将其更改为仅class,即使我能够在它只是在一个时打印真实值<p>.
这是怎么回事?
【问题讨论】:
标签: c# html asp.net-mvc