Having trouble getting help?
Contact Support
Contact Support
Customize the Empty Record Template in ASP.NET Core Grid
13 Mar 20252 minutes to read
The empty record template feature in the Syncfusion ASP.NET Core Grid allows you to use custom content such as images, text, or other components, when the Grid doesn’t contain any records to display. This feature replaces the default message of ‘No records to display’ typically shown in the Grid.
To activate this feature, set the emptyRecordTemplate
property of the Grid. The emptyRecordTemplate
property expects the HTML element or a function that returns the HTML element.
In the following example, an image and text have been rendered as a template to indicate that the Grid has no data to display.
<ejs-grid id="Grid" dataSource="@ViewBag.data" height="273" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" emptyRecordTemplate= '#emptytemplate'>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" isPrimaryKey="true" validationRules="@(new { required=true, number=true})" width="100"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" validationRules="@(new { required=true})" width="120"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" validationRules="@(new { required= true, number=true })" width="120"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" editType="dropdownedit" validationRules="@(new { required=true})" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script id="emptytemplate" type="text/x-template">
<div class='emptyRecordTemplate'>
<img src="@Url.Content("~/image/emptyRecordTemplate.svg")" class="e-emptyRecord" alt="No record">
<span>There is no data available to display at the moment.</span>
</div>
</script>
<style>
.emptyRecordTemplate {
text-align: center;
}
.e-emptyRecord {
display: block;
margin: 10px auto;
}
</style>
public IActionResult Index()
{
ViewBag.DataSource = OrderDetails.GetAllRecords();
return View();
}