Customize the Empty Record Template in ASP.NET MVC Grid

12 Mar 20251 minute to read

The empty record template feature in the Syncfusion ASP.NET MVC 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.

@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).EmptyRecordTemplate("#emptytemplate").Columns(col =>
{
    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).ValidationRules(new { required = true, number=true }).Add();
    col.Field("CustomerID").HeaderText("Customer Name").Width("150").ValidationRules(new { required = true}).Add();
    col.Field("Freight").HeaderText("Freight").Width("120").Format("C2").EditType("numericedit").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).ValidationRules(new { required = true, number=true }).Add();
    col.Field("ShipCountry").HeaderText("Ship Country").Width("150").EditType("dropdownedit").ValidationRules(new { required = true}).Add();
}).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
<script id="emptytemplate" type="text/x-template">
    <div class='emptyRecordTemplate'>
        <img src="@Url.Content("~/images/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();
}

Empty Record Template