I am iterating round a model's comments (a collection of Comment
objects), and need to style them based on whether the property Private
is true
or false
.
I tried to add a class based on a property like this:
<div class="contact-card comment_p_@(comment.Private)">
But the generated html keeps giving me
<div class="contact-card comment_p_class">
Even though I have directly below this element
<p>@comment.Private</p>
which outputs <p>True</p>
or <p>False</p>
as appropriate.
Here is the full loop:
@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>
}
And output of one iteration:
<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>
I also tried
<div class="contact-card comment_p_@comment.Private">
<div class="@comment.Private">
<div class="comment-@comment.Private">
But I always get the same results...when I try to set the class using the property, the output html changes it to just class
, even though I am able to print the true value when its just in a <p>
.
What is going on here?