How to create CRUD app in ASP.NET Core-Razor Pages

Search for a command to run...

No comments yet. Be the first to comment.
Modern software systems often separate control logic from high-performance execution logic. This design is common in networking, distributed systems, operating systems, storage engines, and embedded s

Introduction Engineering software often combines multiple programming languages to leverage their individual strengths. A common approach is to implement computational algorithms in native C or C++ wh

Deadlocks are one of the most common synchronization problems encountered in operating systems and concurrent programming. Although the concept is frequently introduced in textbooks, observing it insi

Memory and resource allocation are fundamental operations inside the Linux kernel. Whether assigning device IDs, managing CPU masks, allocating interrupt vectors, or tracking hardware resources, the k

The Linux scheduler is one of the most important components of the operating system. Every running program, background service, and kernel thread eventually interacts with the scheduler. In this artic

Razor Pages is a one more web application programming model of ASP-dot-NET Core. It removes much of the ceremony of ASP-dot-NET MVC by adopting a file-based routing approach. Each Razor Pages file found under the Pages directory correlate to endpoint. Razor Pages have an associated C# objected called the page model, which holds each page's behaviour. Additionally, each page works on the limited semantics of HTML, only supporting GET and POST methods.
You are going to create simple ASP-dot-NET Core - Razorpages app
Ubuntu-20.04 +jit [linux-x86_64]
,NET Core 3.1.416
Sqlite 3.31.1
Beginner
Knowledge of C# and text editor/visual studio code
$ dotnet new webapp -o AspStud
The dotnet new command creates a new Razor Pages project in the AspStud folder.
comment the app.UseHttpsRedirection(); in Startup.cs file( for running on ubuntu )
give following command at terminal$ dotnet build
$ dotnet run
Create folder Models
Add Stud.cs file
The Movie class contains: The ID field is required by the database for the primary key. [DataType(DataType.Date)]: The DataType attribute specifies the type of the data (Date).
dotnet tool install --global dotnet-ef --version 3.1.9
dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4
dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 3.1.9
dotnet add package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore --version 3.1.9
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 3.1.4
dotnet add package Microsoft.EntityFrameworkCore.Design --version 3.1.9
dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 3.1.9
dotnet add package Microsoft.Extensions.Logging.Debug --version 3.1.9
Here is the complete AspStud.csporj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.9" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
</ItemGroup>
</Project>
Create folder Data
Add AspStudContext.cs file
add sqlite conntection string in appsetting.json file
Run the following .NET Core CLI commands:
$dotnet ef migrations add InitialCreate$ dotnet ef database update
The migrations command generates code to create the initial database schema. The schema is based on the model specified in DbContext. The InitialCreate argument is used to name the migrations.
& dotnet run
After performing above steps, you made a base ASP-dot-NET Core -Razorpages basic app. Also in this tutorial you have explored sqlite database connection string, migration, dbcontext class etc.Keep in mind that scaffolding command dotnet-aspnet-codegenerator razorpage -m AspStudContext -udl -outDir Pages/Studs --referenceScriptLibrariesis not working in dotnet CLI on ubuntu, scaffolding command work only on with visual studio on window.