Abstract

Managing inventory is a common challenge for small businesses, including event rental companies. In this article, we’ll build a simple, beginner-friendly inventory management feature using ASP.NET Core MVC and Entity Framework Core. This example can be applied to many business types, including party rental services, equipment lenders, or local service providers.

Introduction

Inventory tracking is essential for any service-based business that rents, lends, or schedules equipment. In this walkthrough, we will:

This is a practical starting point for building a full rental management platform.

Project Setup

1. Create a New ASP.NET Core MVC Project

Use the .NET CLI:

dotnet new mvc -n RentalInventoryDemo
cd RentalInventoryDemo

Install Entity Framework Core packages:

dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools

Creating the Data Model

2. Define the Inventory Item Model

Create a new folder named Models and add InventoryItem.cs.

using System.ComponentModel.DataAnnotations;

namespace RentalInventoryDemo.Models
{
    public class InventoryItem
    {
        public int Id { get; set; }

        [Required]
        public string ItemName { get; set; }

        [Range(0, int.MaxValue)]
        public int QuantityAvailable { get; set; }

        public string Category { get; set; }
    }
}

Configuring the Database Context

3. Add ApplicationDbContext

Create a Data folder → add ApplicationDbContext.cs.

using Microsoft.EntityFrameworkCore;
using RentalInventoryDemo.Models;

namespace RentalInventoryDemo.Data
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options) { }

        public DbSet<InventoryItem> InventoryItems { get; set; }
    }
}

Register it in Program.cs

Add:

builder.Services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

Add a connection string in appsettings.json:

"ConnectionStrings": {
  "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=RentalInventoryDb;Trusted_Connection=True;"
}

Add EF Core Migrations

4. Create and Apply Database Schema

dotnet ef migrations add InitialCreate
dotnet ef database update

This creates the database and the InventoryItems table.

Building the CRUD Pages

5. Scaffold a Controller and Views

Use the built-in scaffolder:

dotnet aspnet-codegenerator controller \
  -name InventoryController \
  -m InventoryItem \
  -dc ApplicationDbContext \
  --relativeFolderPath Controllers \
  --useDefaultLayout \
  --referenceScriptLibraries

This generates:

Viewing the Inventory List

The generated Index.cshtml will look like this (simplified):

@model IEnumerable<RentalInventoryDemo.Models.InventoryItem>

<h2>Inventory</h2>

<p>
    <a asp-action="Create">Add New Item</a>
</p>

<table class="table">
    <thead>
        <tr>
            <th>Item Name</th>
            <th>Quantity Available</th>
            <th>Category</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
@foreach (var item in Model)
{
    <tr>
        <td>@item.ItemName</td>
        <td>@item.QuantityAvailable</td>
        <td>@item.Category</td>
        <td>
            <a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
            <a asp-action="Details" asp-route-id="@item.Id">Details</a> |
            <a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
        </td>
    </tr>
}
    </tbody>
</table>

Result

You now have a working inventory management module with:

This is the foundation of a complete rental management system.

Next Steps

You can extend this project by adding:

Conclusion

ASP.NET Core combined with Entity Framework Core provides a clean and efficient way to build business tools like inventory systems. Whether you’re managing party rentals, equipment, or supplies, the structure above gives you a solid foundation to build on.

If you’d like, I can create follow-up articles on:

Just tell me!