JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › General Discussions › responseHandler in blazor › Reply To: responseHandler in blazor
Hi Nguyễn Thành,
responseHandler requires a JS callback function. So to use it in Blazor, you will need JS Interop.
For example:
@using Microsoft.JSInterop
@inject IJSRuntime JS
protected override void OnInitialized() {
base.OnInitialized();
JS.InvokeVoidAsync(“addResponseHandler”);
}
In the _Host.cshml, or index.html depending on whether you use Server-side or WASM Blazor, add this;
<script>
window.addResponseHandler = () => {
const fileUpload= document.querySelector(‘smart-file-upload’);
fileUpload.responseHandler = function(xhr){ if(xhr.status === 404) {console.log(‘Not Found’);}};
}
</script>
If you wish to use only Blazor with no JS, you can also use the OnUploadCompleted and OnUploadError events.
Best Regards,
Ivan Peevski
Smart HTMLElements Team
https://www.htmlelements.com/