❔ System.NullReferenceException 'Object reference not set to an instance of an object.'

Hello! I'm getting a little desperate here: This is my index code:
public IActionResult Index()
{
// List<Tipo> list = _context.Tipos.ToList();
List<string> list = new List<string>();
list.Add("Home");
list.Add("Home");
list.Add("Home");
list.Add("Home");
return View(list);
}
public IActionResult Index()
{
// List<Tipo> list = _context.Tipos.ToList();
List<string> list = new List<string>();
list.Add("Home");
list.Add("Home");
list.Add("Home");
list.Add("Home");
return View(list);
}
This is my index.cshtml:
<select class="form-select" name="tipo" id="tipo">
@foreach (var item in Model)
{
<option value="abc">abc</option>
}
</select>
<select class="form-select" name="tipo" id="tipo">
@foreach (var item in Model)
{
<option value="abc">abc</option>
}
</select>
Why do I get this exception? I've been at it for over an hour, I'm new at this, and I'm very confused
5 Replies
Saber
Saber2y ago
where is the exception occuring
Marcoelho97
Marcoelho97OP2y ago
At the Foreach, the "Model" part
Saber
Saber2y ago
is this happening when the page first loads, or after you try to submit a form or something? As is, it seems fine
Marcoelho97
Marcoelho97OP2y ago
When I try to run the app ._.' Closed the project, re-opened and my HomeController had gone to its initial state Tried doing the exact same thing, it's now working, for some reason :|
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server