A full-featured CRUD (Create, View, Update, Delete) web application built with ASP.NET Core using Razor Pages and Entity Framework Core scaffolding.
- Create: Add new records to the database
- View: View and search through existing records
- Update: Edit and modify existing records
- Delete: Remove records from the database
- Responsive web interface using Bootstrap
- Server-side validation
- Entity Framework Core for data access
- Scaffolded Razor Pages for rapid development
- SQL Server database integration
- ASP.NET Core 8.0 (or your specific version)
- Razor Pages
- Entity Framework Core
- SQL Server (or your database provider)
- Bootstrap 5 for responsive UI
- C#
- HTML/CSS/JavaScript
Before running this application, make sure you have the following installed:
- .NET 8.0 SDK (or your specific version)
- Visual Studio 2022 or Visual Studio Code
- SQL Server (LocalDB, Express, or full version)
- SQL Server Management Studio (optional, for database management)
-
Clone the repository
git clone https://github.com/yourusername/your-crud-app.git cd your-crud-app
-
Restore NuGet packages
dotnet restore
-
Build the project
dotnet build
-
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;" } }
-
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
-
Run the application
dotnet run
-
Access the application
Open your web browser and navigate to:
https://localhost:5001
(HTTPS)http://localhost:5000
(HTTP)
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
- HomeController.cs - Main controller handling home page and employee-related actions
- EmployeeDbContext.cs - Entity Framework database context for employee data
- EmployeeModel.cs - Employee entity model
- ErrorViewModel.cs - Model for error handling and display
- Home Views - Complete set of CRUD operation views:
Index.cshtml
- Main listing pageCreate.cshtml
- Employee creation formEdit.cshtml
- Employee editing formDetails.cshtml
- Employee details viewDelete.cshtml
- Employee deletion confirmationPrivacy.cshtml
- Privacy policy page
- appsettings.json - Application configuration settings
- Program.cs - Application entry point and configuration
- .gitignore / .gitattributes - Git configuration files
- Migrations/ - Entity Framework database migration files
This structure follows standard ASP.NET Core MVC conventions with a clear separation of concerns between models, views, and controllers.
- Navigate to the main page
- Click "Create New" button
- Fill in the required fields
- Click "Create" to save the record
- The main page displays a list of all records
- Click "Details" to view complete information for a specific record
- Click "Edit" next to the record you want to modify
- Update the necessary fields
- Click "Save" to apply changes
- Click "Delete" next to the record you want to remove
- Confirm the deletion on the confirmation page
The application uses Razor Pages, but the following page routes are available:
GET /Home
- List all recordsGET /Home/Create
- Show create formPOST /Home/Create
- Create new recordGET /Home/Details/{id}
- Show record detailsGET /Home/Edit/{id}
- Show edit formPOST /Home/Edit/{id}
- Update recordGET /Home/Delete/{id}
- Show delete confirmationPOST /Home/Delete/{id}
- Delete record
Update the connection string in appsettings.json
to point to your database server.
The application supports different environments (Development, Staging, Production). Use appsettings.{Environment}.json
files for environment-specific settings.
-
Database Connection Errors
- Verify your connection string is correct
- Ensure SQL Server is running
- Check if the database exists
-
Migration Errors
- Delete the Migrations folder and recreate migrations
- Ensure your model classes are properly configured
-
Build Errors
- Run
dotnet clean
followed bydotnet build
- Check for missing NuGet packages
- Run