My attempts to run a NET call from JS ended in failure.Tried including examples from Microsoft.But adding to the page
@rendermode InteractiveServerSo that the button would work. Causes an error.
Here is the code that worked in .NET 7
async Task Up(){ await JS.InvokeVoidAsync("Crop.responses", DotNetObjectReference.Create(this), Id); crop2View = "opcity-0";}[JSInvokable]public async void ResponseMethod(string data){ model.Base64 = data; await UploadServer(); StateHasChanged();}JS code
var base64data;window.Crop = { responses: function (component, id) { resize.result('blob').then(function (blob) { var reader = new FileReader(); reader.readAsDataURL(blob); reader.onloadend = async function () { base64data = reader.result; var i = document.getElementById('result-'+ id); var img = document.createElement('img'); img.src = base64data; i.appendChild(img); return component.invokeMethodAsync('ResponseMethod', base64data); } }); }};How to call ResponseMethod from JS