ASP.NET Core 8 Razor Pages CRUD - .NET 8 Razor Pages CRUD Using Entity Framework Core and SQL Server
In this video, we are going to create an ASP.NET Razor Pages CRUD app using Entity Framework Core and SQL Server. We will use the .NET 8 Razor Pages template in Visual Studio 2022 to create this CRUD app.
<div class="row mb-3">
<label class="col-sm-4 col-form-label">Name</label>
<div class="col-sm-8">
<input asp-for="ProductDto.Name" class="form-control" />
<span asp-validation-for="ProductDto.Name" class="text-danger"></span>
</div>
</div>
string newFilename = DateTime.Now.ToString("yyyyMMddHHmmssfff");
newFilename += Path.GetExtension(ProductDto.ImageFileName!.FileName);
string ImageFullPath = environment.WebRootPath + "/Images/" + newFilename;
using (var stream = System.IO.File.Create(ImageFullPath))
{
ProductDto.ImageFileName.CopyTo(stream);
}
//Delete Old Image on the server
string OldimageFullPath = environment.WebRootPath + "/images/" + product.ImageFileName;
System.IO.File.Delete(OldimageFullPath);
product.Name = ProductDto.Name;
product.Brand = ProductDto.Brand;
product.Category = ProductDto.Category;
product.Price = ProductDto.Price;
product.Description = ProductDto.Description ?? "";
product.ImageFileName = newFileName;
context.SaveChanges();
Product = product;
successMessage = "Product Updated";
we are going to create an ASP.NET Razor Pages Full CRUD Operations application using Entity Framework Core Code First approach and SQL Server.
We will be using the Core .NET 8 Razor Pages template in Visual Studio 2022 to create this application.
Bootstrap in this ASP.NET Razor Pages website to style our pages.