aspnet-core-crud-app

ASP.NET Core CRUD Application

A full-featured CRUD (Create, View, Update, Delete) web application built with ASP.NET Core using Razor Pages and Entity Framework Core scaffolding.

Features

Technologies Used

Prerequisites

Before running this application, make sure you have the following installed:

Installation

  1. Clone the repository
    git clone https://github.com/yourusername/your-crud-app.git
    cd your-crud-app
    
  2. Restore NuGet packages
    dotnet restore
    
  3. Build the project
    dotnet build
    

Database Setup

  1. Update the connection string

    Open appsettings.json and update the connection string to match your SQL Server instance:

    {
      "ConnectionStrings": {
        "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=YourAppDb;Trusted_Connection=true;MultipleActiveResultSets=true;TrustServerCertificate=true;"
      }
    }
    
  2. Run Entity Framework migrations

    dotnet ef database update
    

    If migrations don’t exist, create them first:

    dotnet ef migrations add InitialCreate
    dotnet ef database update
    

Running the Application

  1. Run the application
    dotnet run
    
  2. Access the application

    Open your web browser and navigate to:

    • https://localhost:5001 (HTTPS)
    • http://localhost:5000 (HTTP)

Project Structure - PracticeWebApplication

PracticeWebApplication/
├── Connected Services/
├── Dependencies/
├── Properties/
├── wwwroot/
├── Controllers/
│   └── HomeController.cs
├── Migrations/
├── Models/
│   ├── EmployeeDbContext.cs
│   ├── EmployeeModel.cs
│   └── ErrorViewModel.cs
├── Views/
│   ├── Home/
│   │   ├── Create.cshtml
│   │   ├── Delete.cshtml
│   │   ├── Details.cshtml
│   │   ├── Edit.cshtml
│   │   ├── Index.cshtml
│   │   └── Privacy.cshtml
│   └── Shared/
│       ├── _ViewImports.cshtml
│       └── _ViewStart.cshtml
├── .gitattributes
├── .gitignore
├── appsettings.json
├── Program.cs
└── README.md

Key Components

Controllers

Models

Views

Configuration

Database

This structure follows standard ASP.NET Core MVC conventions with a clear separation of concerns between models, views, and controllers.

Usage

Creating Records

  1. Navigate to the main page
  2. Click “Create New” button
  3. Fill in the required fields
  4. Click “Create” to save the record

Viewing Records

Updating Records

  1. Click “Edit” next to the record you want to modify
  2. Update the necessary fields
  3. Click “Save” to apply changes

Deleting Records

  1. Click “Delete” next to the record you want to remove
  2. Confirm the deletion on the confirmation page

API Endpoints

The application uses Razor Pages, but the following page routes are available:

Configuration

Database Configuration

Update the connection string in appsettings.json to point to your database server.

Environment Settings

The application supports different environments (Development, Staging, Production). Use appsettings.{Environment}.json files for environment-specific settings.

Troubleshooting

Common Issues

  1. Database Connection Errors
    • Verify your connection string is correct
    • Ensure SQL Server is running
    • Check if the database exists
  2. Migration Errors
    • Delete the Migrations folder and recreate migrations
    • Ensure your model classes are properly configured
  3. Build Errors
    • Run dotnet clean followed by dotnet build
    • Check for missing NuGet packages

Watch the video