© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
12 replies
IamMax420

I'm getting an error "object reference not set to an instance of an object"

the code:
@model IEnumerable<WebApp.Models.Produkt>

<h1>a List</h1>

@if (Model == null || !Model.Any())
{
    <p>No products available.</p>
}
else
{
    @foreach (var product in Model)
    {
        if (product != null)
        {
            <li>
                <b>@product.name</b> - @product.category
                <a href="@Url.Action("Details", "Warehouse", new { id = product.id })">Details</a>
                <button>Delete</button>
            </li>
        }
    }
}
@model IEnumerable<WebApp.Models.Produkt>

<h1>a List</h1>

@if (Model == null || !Model.Any())
{
    <p>No products available.</p>
}
else
{
    @foreach (var product in Model)
    {
        if (product != null)
        {
            <li>
                <b>@product.name</b> - @product.category
                <a href="@Url.Action("Details", "Warehouse", new { id = product.id })">Details</a>
                <button>Delete</button>
            </li>
        }
    }
}


It appears that Model is null but I don't know how to fix it
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

object reference not set to an instance of object error
C#CC# / help
2y ago
✅ Object reference not set to an instance of an object.
C#CC# / help
10mo ago
"Object reference not set to an instance of an object"
C#CC# / help
17mo ago