I want to go back from the Create Page to the Index Page which is in the Database and it still does not have any data.
This is the code in index page:
@if (Model.Books.Count() > 0 )
{
<table class="table table-bordered table-striped">
<tr class="table-secondary">
<th>
<label asp-for="Books.FirstOrDefault().Name"></label>
</th>
<th>
@Html.DisplayNameFor(a => a.Books.FirstOrDefault().Author)
</th>
<th>
<label asp-for="Books.FirstOrDefault().ISBN"></label>
</th>
<th>
</th>
</tr>
@foreach (var data in Model.Books)
{
<tr>
<td>
@Html.DisplayFor(a => data.Name)
</td>
<td>
@Html.DisplayFor(a => data.Author)
</td>
<td>
@*using html helper to display the data*@
@Html.DisplayFor(a=>data.ISBN)
</td>
<td>
<button class="btn btn-success btn-sm">Edit</button>
<button class="btn btn-danger btn-sm">Delete</button>
</td>
</tr>
}
</table>
}
else
{
<p class="text-center text-danger">No Book Available.<br /><b>Please create a book !!</b></p>
}
When it is directly from Home to the Index Page it will go to the else
statement , but from Create Page to the Index , an error is occurred.
I would like to know how to handle this exception or this error ?
I think it is not practical to develop without any dummy data but just for knowledge.
Is there any idea ?