Introduction
In the world of web application development, the ability to efficiently handle bulk data uploads is a common requirement. Whether you're dealing with customer information, product catalogs, or any other type of data, providing a seamless and user-friendly bulk upload experience can significantly improve your application's functionality and user satisfaction.
Prerequisites
Before we dive into the implementation details, ensure that you have the following in place:
- A Blazor Server project is set up in your development environment.
- The Radzen.Blazor NuGet package installed in your project.
- A basic understanding of Blazor and Razor syntax.
Step 1. Setting up the Razor Page
Let's start by creating a new Razor Page named `BulkUploadRecords.razor` in the `Pages` folder of your Blazor Server project.
@page "/bulk-upload-records"
@using BulkUpload.Data
@using Radzen
@using Radzen.Blazor
<style>
.rz-sortable-column {
min-width: 180px;
border-bottom: 1px solid #000;
}
</style>
<section class="body-wrapper">
<div class="container-fluid">
<div>
<RadzenLabel Text="Please upload a CSV file" class="form-label required lead px-0" />
</div>
<div>
<InputFile Accept=".csv" OnChange="OnInputFileChange" class="input-file-uploader" id="uploadalldocs" />
</div>
@if (null != Records && Records.Count > 0)
{
<RadzenDataGrid class="mt-4" AllowAlternatingRows="false" AllowFiltering="true" AllowPaging="true" PageSize="10" AllowSorting="true"
Data="@Records" TItem="ImportDataModel" @ref=grid
FilterMode="FilterMode.Advanced" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" AllowColumnResize="false" LogicalFilterOperator="LogicalFilterOperator.Or">
<Columns>
<RadzenDataGridColumn TItem="ImportDataModel" Filterable="false" Sortable="true" Property="FirstName" Title="First Name" TextAlign="TextAlign.Left">
<EditTemplate Context="application">
<RadzenTextBox @bind-Value="application.FirstName" Style="width:100% !important; display: block" Name="FirstName" />
</EditTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ImportDataModel" Filterable="false" Sortable="true" Property="LastName" Title="Last Name" TextAlign="TextAlign.Left">
<EditTemplate Context="application">
<RadzenTextBox @bind-Value="application.LastName" Style="width:100% !important; display: block" Name="LastName" />
<RadzenRequiredValidator Text="Last name is required" Component="LastName" Popup="false" />
<RadzenRegexValidator Component="LastName" Text="Invalid Last Name" Popup=false />
</EditTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ImportDataModel" Filterable="false" Sortable="true" Property="Email" Title="Email" TextAlign="TextAlign.Left">
<EditTemplate Context="application">
<RadzenTextBox @bind-Value="application.Email" Style="width:100% !important; display: block" Name="Email" />
</EditTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ImportDataModel" Filterable="false" Sortable="true" Property="Phone" Title="Phone" TextAlign="TextAlign.Left">
<EditTemplate Context="application">
<RadzenTextBox @bind-Value="application.Phone" Style="width:100% !important; display: block" Name="Phone" />
</EditTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
}
</div>
</section>
In this Razor Page, we have the following key elements:
- Styles: We define custom CSS styles for the Radzen Datagrid columns, setting a minimum width and a border-bottom.
- File Upload Section: This section includes a label and an `InputFile` component that allows the user to select a CSV file for upload.
- Radzen Datagrid: The Datagrid is conditionally rendered when there are records available. It includes features like sorting, filtering, pagination, and inline editing.
- Datagrid Columns: We define the columns for the Datagrid, including `FirstName`, `LastName`, `Email`, and `Phone`. Each column has a custom `EditTemplate` that allows the user to edit the data directly in the Datagrid.
- Validation: We apply validation rules, such as a required field for the `LastName` column and a regex validator for the `LastName` column.

Join the conversation! Your thoughts help the community grow.