I am just trying to create a small prototype application in Visual Studio using .Net 5/Blazor server app, where I need to have Bootstrap collapse functionality in a Blazor component - this would contain a separate Blazor component when expanded.
I am trying to avoid where possible to use JavaScript or jQuery in the prototype as much as possible. However, I can see that in some cases such as Bootstrap Collapse I may need to do this. I would like to have code local to the component if possible, but ok to having a .js file containing common helper functions if needed.
The code below gives an example with some ideas on how I might do this - does anyone have any ideas on how to get this to work.
<div class="btn btn-primary" @onclick="ViewDetails" data-toggle="collapse" role="button" aria-expanded="false" aria-controls="details">
this is some text for a button
</div>
<div class="collapse" id="details">
this is the details screen for this record
</div>
@code {
private async void ViewDetails()
{
// Button click indicates an event so should be able to get redraw to occur.
// Some mechanism to change the toggle state without calling javascript (dhtml style)
// Use a boolean to change the ARIA state or something like that
_viewDetails = (_viewDetails == false) ? true : false;
this.StateHasChanged();
// Or, call inline jquery to toggle control (preferred) something like.
await _JSRuntime.InvokeVoidAsync("$('#details).collapse('toggle');", "");
}
}