I am getting a runtime error with my application when I try to go from one View to another;
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Which points to 'Countries' in the following code of the View I am trying to access;
@model Customer
...
<div class="form-group">
<label asp-for="Country">Country</label>
<select asp-for="Country" class="form-control">
<option value="">Select a country...</option>
@foreach (Country c in ViewBag.Countries) //Error
{
<option value="@c.CountryID">@c.Name</option>
}
</select>
</div>
....
I am also getting an error when initializing and updating the database and I'm uncertain if they're related;
Error Number:2714,State:6,Class:16
There is already an object named 'Countries' in the database.
Let me know if there is any other code sample I can provide to clarify.