Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #103493
    Nguyễn Thành
    Participant

    how to use responseHandler in blazor ? when i add attribute responseHandler =”@myObject” then the interface will be lost

    #103495
    A&M Detailing
    Participant

    Nice post, thanks for sharing here.

    #103496
    ivanpeevski
    Participant

    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/

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.