From the course: Advanced Blazor WebAssembly

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Solution

Solution

(bright upbeat music begins) - [Instructor] How did you do? Here is a way you can get the form to work. Underneath the form element, add the InputFile component. This will allow for the user to add the file to the form. Then add the unchanged attribute and use it to set the OnInput file change method. The second task is to get the upload image button working, so it uploads the image when pressed. Add the at one click attribute to the button and set it with the UploadImageAsync method. Finally, show a message when an image has been uploaded. Do an if statement on the uploaded property. If it's true, set a message like the file has been successfully uploaded. Let's test this out, by uploading the image from the snippet folder. Pressin' the Upload Image button successfully uploads the image to the server and a successful message is displayed to the user.

Contents