Is there any way to have a specific card show its own text when you click the show text button. I’ve tried several different ways of manipulating CSS, it doesn’t work
@foreach(var note in noteViewModels)
{
<div class="m-2">
<div class="d-flex justify-content-around" style="background-color: darkgray">
<p>@note.NoteModel.Title</p>
<p>@note.NoteModel.CreateDate</p>
<div>
<button class="btn bg-dark text-light" @onclick="()=>DetailsButtonHandler(note)">View Text</button>
<button class="btn bg-dark text-light">Edit Card</button>
</div>
</div>
<div style="background-color:lightgray;">
<div class="m-0 p-1">
<p class="m-2 p-2 bg-light">@note.NoteModel.Text</p>
</div>
</div>
</div>
}
help me pls i dont know what to do
2
Answers
There’s various ways you can do this.
Since you’re working with a collection of Notes then the simplest way would be to add a property to the
Note
classUsing an
@if
statement in the markup to control what to show and hide.The button clicks pass the specific
note
to the handler method, where you change theIsShowText
property.Or, you can use CSS classes/properties. Where you use the
@()
block to write C# code in.In the example below i’m adding the bootstrap
d-none
class based on theIsShowText
property of the note on this line,class='@(note.IsShowText?"":"d-none")'
.Both methods demos
Well, if you want to individually toggle each item, you need to either add a
bool ShowText
to the Notes class itself, or create a dictionary with each instance as a key, and a boolean as the value. Here’s an example of the latter.