التخطي إلى المحتوى الرئيسي

المشاركات

عرض الرسائل ذات التصنيف ASP.NET CORE MVC

LINQ to ASP.NET CORE MVC by Shiva Sir

 🔷 What is LINQ? LINQ (Language Integrated Query) is a .NET feature that allows you to query collections (like arrays, lists, and database entities) in a SQL-like or method-chaining syntax directly within C# code. 🔷 Types of LINQ Syntax: Query Syntax (SQL-like) Method Syntax (Fluent/Chaining) Mixed Syntax (Less common) 🔷 Common LINQ Operations Operation Example (Method Syntax) Where .Where(x => x.Age > 18) Select .Select(x => x.Name) OrderBy .OrderBy(x => x.Name) GroupBy .GroupBy(x => x.Department) Join .Join(..., ..., ..., ...) Any, All, Count, FirstOrDefault, Take, Skip, etc. 🔷 ASP.NET Core MVC Example: Student Management System Step 1: Setup Entity Models/Student.cs public class Student {     public int Id { get; set; }     public string Name { get; set; }     public int Marks { get; set; }     public string Subject { get; set; } } Step 2: Create a Fake List for LINQ Demo Controllers/StudentController.cs us...

Razor form example in ASP.NET Core MVC

Complete Razor form example in ASP.NET Core MVC demonstrating all major form elements: How to Create Form Element in Razor Form Type Element Used Textbox <input asp-for="Name" /> Radio Button <input type="radio" asp-for="Gender" /> Checkbox <input type="checkbox" asp-for="IsSubscribed" /> ListBox <select multiple asp-for="SelectedSkills" /> DropdownList <select asp-for="SelectedCountry" />  Create Registration Form using Razor Form Elements: Create Model: UserFormModel.cs public class UserFormModel {     public string Name { get; set; }     public string Gender { get; set; }     public bool IsSubscribed { get; set; }     public List<string> SelectedSkills { get; set; }     public string SelectedCountry { get; set; }     public List<string> Countries { get; set; }     public List<string> Skills { get; set; } } Create Controller: FormController.cs using Mi...

Code First Approach in .NET Core MVC

Code First Approach in ASP.NET Core MVC? Code First is complete dynamic approach of entity framework where we create database configuration and table dynamically using dB Context class.  1)  Create Web Project using ASP.NET Core MVC Project Template 2)  Add Library from Nuget Package EntityFrameworkCore.Design EntityFrameworkCore.SQLServer EntityFrameworkCore.Tools 3) Create Local Database using Server Explorer 4)  Create Model Class Like this using System.ComponentModel.DataAnnotations; namespace WebApplication3.Models {     public class Employee     {         [Key]         public int Id { get; set; }         public string Name { get; set; }             public string Email { get; set; }         public string Mobileno { get; set; }     } } 5)  Create DbContext class using Microsoft.EntityFrameworkCore; namespace WebAppl...

Database connectivity in ASP.net core , .NET Core DB Connection, step by step

Database connectivity in ASP.net core , .NET Core DB Connection, step by step  Step1st: Create ASP.NET Core Project Step2nd: Manage Nuget Package Manager Console  Microsoft.EntityFrameworkCore 7.0 Microsoft.EntityFrameworkCore.SqlServer 7.0 Microsoft.EntityFrameworkCore.Tools 7.0 Step3rd: Create Model Class namespace WelcomeProject.Models {     public class Product     {         public int Id { get; set; }         public string Name { get; set; }         public decimal Price { get; set; }     } } Create AppDbContext Class also under model using Microsoft.EntityFrameworkCore; using System.Collections.Generic; namespace WelcomeProject.Models {     public class AppDbContext : DbContext     {         public DbSet<Product> Products { get; set; }         private readonly IConfiguration _configuration;         ...

How to upload file in ASP.NET Core MVC, File uploading concept in .net core MVC

 How to  upload file in  ASP.NET Core MVC, File uploading concept in .NET  core MVC:- It is used to upload any external content such as audio, video, text and doc file under project. Microsoft provide IFormFile class to handle file uploading operation Step by Step Implementation 1)  Create Project 2)  Create FileUpload.cs class under Models folder public class FileUpload     {         public IFormFile FormFile { set; get; }     } 3)  Create FileUploadingController Class using Microsoft.AspNetCore.Mvc; using CodeFirstExample.Models; using Microsoft.Extensions.Hosting.Internal; namespace CodeFirstExample.Controllers {     public class FileUploadController : Controller     {         private IWebHostEnvironment Environment;         public FileUploadController(IWebHostEnvironment _environment)         {         ...

Code First Approach in ASP.NET CORE MVC

 How to implement Code First Approach in ASP.NET CORE MVC:- Code First Approach is best for light-weight and smaller project in ASP.NET MVC Core, it is basically created to those developer who is not know about SQL. without SQL Server or any database package developer can create complete project. Step 1 New Project Once you have installed the Visual Studio 2019 and .Net Core 3.1 SDK, you can start building a new ASP.NET Core Application. Step 2nd:- Create a web app and From the Visual Studio select Create a new project. Select ASP.NET Core Web Application > Next. Step 3rd:- Give your project a name i.e. SampleCodeFirstExample and give your project a location where it’ll be saved and click Create. Step4th:-  Install the NuGet Packages From the Solution right click on dependency, select Manage NuGet Packages and Select the Browse tab, and then enter Microsoft.EntityFrameworkCore.SqlServer in the search box, select Latest Stable Version and Install. Step5h:- Now, install ...

How to perform CRUD Operation in .NET CORE using Database First Approach:- BY Shiva Sir

 How to perform CRUD Operation in .NET CORE using Database First Approach:-  BY Shiva Sir:- Database First means you should create database and table from Database end and Program Code and Business Logic from application end. Database first most useful approach in Entity framework for large projects. 1)  Create Database  2)  Create Table 3)  Create .NET MVC Project 4)  MICROSOFT.ENTITYFRAMEWORKCORE.SqlServer MICROSOFT.ENTITYFRAMEWORKCORE.TOOLS MICROSOFT.ENTITYFRAMEWORK.CORE 5)  WRITE THIS COMMAND to GENERATE CONTEXT CLASS AND MODEL CLASS. Scaffold-DbContext "Data Source=(localdb)\ProjectsV13;Initial Catalog=Northwind; Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;"  -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models/DB 6)  go into appsetting.json file and create connection String {   "Logging": {     "LogLevel": {       "Default": "Information", ...