I have a partial, which could be re-used many times in the same view.
It hosts a chartjs element.
The Partial loads, makes an ajax call to get its data.
The various keys of the Chart are populated from the returned data and executes and chart loads.
The partial's canvas and containing div are uniquely identified by a numeric counter of partials on the parent page which iterates using Razor to build the divs and canvases for each chart.
All good.
e.g.
@{
divId = "divDetail" + ViewBag.ChartIndex.ToString();
canvasId = "canvas" + ViewBag.ChartIndex.ToString();
}
<div id="@divId">
<canvas id="@canvasId" style="background-color:black;">
@Html.Partial("ChartPartial", Model)
</canvas>
</div>
But, the chart has an 'onClick' key, which I populate with ChartClick0, ChartClick1 etc. in the Data controller action called by ajax.
How do I dynamically create a script called ChartClick0 or ChartClick1 such that the correct function per Chart is called and executed?
I tried New Function and variations on ViewBag in the parent screen, but no luck. With New Function, I can't concatenate the 'canvas' and the index to produce the new function.