How can I call a method for a <button> where I build the html up as a string?

34 views Asked by At

This is for a Blazor InteractiveServer app. I am creating the html for an Azure Maps popup. I create the html as follows:

var html = new StringBuilder("<div style=\"padding:10px;color:black\"><p>Click to go to the specific profile</p><ul>");
foreach (var pin in clusters)
{
    var name = ConvertToString(pin.Properties["Name"]);
    var url = ConvertToString(pin.Properties["ProfileUrl"]);
    var id = ConvertToInt(pin.Properties["Id"]);
    html.Append($"<li><button @onclick=\"OnSelectPin(id)\">{name}</button></li>");
}
html.Append("</ul></div>");

When the user clicks - it does not call the OnSelectPin() method.

private void OnSelectPin(int id)
{
    // do something
}

How can I get the html I pop up to call OnSelectPin()?

0

There are 0 answers