Reputation: 68
How we show message in table if Model is null or Model have nothing items. How to show “No records found” message if there is no data available in MVC table
<tbody>
@if (Model.Count() > 0)
{
foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.CampaignTitle)</td>
<td>@Html.DisplayFor(modelItem => item.ClientName)</td>
<td>@(item.StartDate == null ? "" : ((DateTime)item.StartDate).ToString("MM/dd/yyyy"))</td>
<td>@(item.EndDate == null ? "" : ((DateTime)item.EndDate).ToString("MM/dd/yyyy"))</td>
<td>@Html.DisplayFor(modelItem => item.ProductCategoryName)</td>
<td>
@if (item.IsActive == 0)
{
@Html.DisplayName("Pending")
}
@if (item.IsActive == 1)
{
@Html.DisplayName("Approved")
}
@if (item.IsActive == 2)
{
@Html.DisplayName("Rejected")
}
</td>
</tr>
}
}
else
{
//No record found
}
</tbody>
in above code else portion i want to show text like "No record Found"
Upvotes: 0
Views: 1116
Reputation: 3839
You can simply create one cell with formatted text ("No record Found") inside else block like here:
<tr>
<td><div style="<some style>">No record Found</div></td>
</tr>
Upvotes: 1