Hi,
This should be working in VS code just clean you solution and build it again
In the VS Code terminal just run those commands
- dotnet clean
- dotnet build
Also, you can disable the null refence compiler warning in .csproj file just replace <Nullable>enable</Nullable> to <Nullable>disable</Nullable>
public class HomeController : Controller
{
private readonly List<string> _poducts;
public HomeController(ILogger<HomeController> logger)
{
_poducts = new List<string>
{
"Ruler",
"Eraser",
"Pen",
"Pencil",
"Notebook",
"Book"
};
}
public IActionResult Index()
{
return View(_poducts);
}
}
The razor page
@model List<string>
<div class="text-center">
@foreach(var item in Model)
{
<h1>@item</h1>
}
</div>