The previous post covered how to perform CRUD operations in a Blazor Web Assembly-based application. In that post, we create a comprehensive UI-based Employees component. In the demonstration, we saw how to populate the employee list, add new Employees, and perform other activities. The file uploader capability in the Blazor Web Assembly will be covered in this article. We will upload the employee profile picture-related file and then display that information in the Employee List and other associated segments.
Create a Database Structure to store Employee Profile Picture information
Before coding into the Blazor Application, we must implement the Database structure changes related to the employee profile pictures. So, related that create the below table in the database.
Add Employee Profile Image into the Employee Add/Update Operation
We have already created the Database structure to capture the Employee Profile Information. Now, we first need to make the related model class. So, Add a new class file called EmployeeProfilePic within the Model folder and add the below code into that file.
Now, open the Employee.cs model class from the Model folder and add the below properties at the end related to capturing the profile file information.
Now, open the EmployeeInfo.razor component file. In that file, after the Phone, no Section, add the below file uploader-related code.
Now, in the same EmployeeInfo.razor file, add the below code into the @code section related to reading the uploaded file, and convert the file information to base64 format.
Now, open the EmployeeController.cs File and replace the SaveEmployee() related code with the below one.
Now, run the application and create a new Employee with a profile picture.
Retrieve Employee Profile Picture to display in Employee List
We saved the employee profile picture already. We need to display that profile picture on the employee list. First, we must make the code changes below in the GetEmployees() method.
Now, also, make the below code changes for the retrieve employee information by the Id method –
Now, open the EmployeeList.razor view component and add the below code in the HTML section to display the profile image –
Now, run the application to check the employee list data.
Now, click on the Employee Name link to display the employee information in the details view.
Happy coding!
Best and Most Recommended ASP.NET Core 8 Hosting
Fortunately, there are a number of dependable and recommended web hosts available that can help you gain control of your website’s performance and improve your ASP.NET Core 8 web ranking. HostForLIFEASP.NET is highly recommended. In Europe, HostForLIFEASP.NET is the most popular option for first-time web hosts searching for an affordable plan.
Their standard price begins at only € 3.49 per month. Customers are permitted to choose quarterly and annual plans based on their preferences. HostForLIFEASP.NET guarantees “No Hidden Fees” and an industry-leading ’30 Days Cash Back’ policy. Customers who terminate their service within the first thirty days are eligible for a full refund.
By providing reseller hosting accounts, HostForLIFEASP.NET also gives its consumers the chance to generate income. You can purchase their reseller hosting account, host an unlimited number of websites on it, and even sell some of your hosting space to others. This is one of the most effective methods for making money online. They will take care of all your customers’ hosting needs, so you do not need to fret about hosting-related matters.