ADNAN ZAMAN
ADNAN ZAMAN

Reputation: 68

No Record Founds text need to show in table if model is null

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

Answers (1)

Vasyl Zvarydchuk
Vasyl Zvarydchuk

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

Related Questions