Complete guide to [Link] Core MVC 3.
1
1. Introduction to Razor Pages in .Net Core 3.1
2. MVC Architecture with .Net Core 3.1
3. Entity Framework Core 3.1
4. Identity Security with EF Core 3.1
5. N-Tier Architecture
6. Dapper and Stored Procedures in EF Core 3.1
7. Repository Pattern
8. Payments using Stripe and BrainTree
9. 2 Factor Authentication, Emails and SMS Notifications
10. Role Management, Session, TempData, Custom Tag Helpers, View Components
and much more…
11. Deployment to Azure
12. Best Practices, Error debugging and Assignments!
CRUD operations
Routing
Action Wizards
[Link]
Gridview Pagination – Customtag helper (Advanced concept)
Delete button – Toaster for notification
Authorized company can send emails, if their email is registered. They will get flexibility
to make payments within 30 days once the order is placed.
Non-authorized company is treated like normal user.
URL for downloading free edition: [Link]/downloads/vs/
Download Visual Studio -> Community 2019
Note: In Visual Studio 2017, .Net Core 3.1 will not work.
[Link]/download/dotnet-core/3.1
Windows (OS) – x64 (Installers)
[Link]/en-us/sql-server/sql-server/downloads
Developer – Download now (Free)
[Link]/en-us/sql/ssms/download-sql-server-management-studio-
ssms?view=sql-server-ver15
[Link]
Introduction to Dapper (.NET 5)
Introduction to [Link] Core MVC (.NET 5)
Evolution of [Link] Core
ASP – 1996
[Link] Webform – 2002
[Link] MVC – 2009
[Link] Core – 2016
[Link] Core 2 – 2017
[Link] Core 3, 3.1 – 2019 Q4
Razor Project
Visual Studio 2019 -> Create a new project
[Link] Core Web Application > Next
Project Name (BookListRazor)
Create a new [Link] Core Web Application (.Net Core/.Net Framework) ([Link] Core
1.0/1.1/2.0/2.1/2.2/3.0/3.1) -> Web Application
Note: Razor Pages will be used inside the Identity in MVC application.
Authentication > Change (No/Individual User Accounts/Work or School
Accounts/Windows)
Razor Pages
o Introduced in [Link] Core 2.0.
o Razor Pages is a new feature of [Link] Core MVC that makes coding page-
focused scenarios easier and more productive.
o Razor Pages is not just for simple scenarios, everything that you can do with MVC
you can do by using Razor Pages like Routing, Models, ActionResult, Tag Helpers
and so on.
o Razor Pages has two parts
1. Razor Page (UI/View)
2. Page Model (Contains Handlers)
Note: [Link] is treated as Razor View or UI of Razor Pages, whereas [Link]
is not code-behind file. It is Page Model.
Note: [Link] consists of OnGet() handler is present. It is like controller action
method.
Note: [Link] Core 1.0 does not create .csproj file, instead, it uses .xproj and
[Link] files to manage the project. This has changed in [Link] Core 2.0. Visual
Studio now uses .csproj file to manage projects.
Steps for adding more packages into our solution:
Tools > NuGet Package Manager > Manage NuGet Packages for Solution…
Browse > [Link] (Select) > Project (Check) and BookListRazor (Check) >
Install (Click).
Note: Every time a package is added into the project, an <ItemGroup>
<PackageReference> entry will get added to [Link] file.
Where is the Meta Package?
[Link] was the metapackage which contains all features of .Net Core.
Prior to .Net Core 3, metapackage was included as a NuGet package.
With .Net Core 3 onwards, meta package is a part of .Net Core installation itself, so
you do not have to include that in the project reference anymore.
LaunchSettings
Properties > [Link] – This file will consist of the settings to be applied after
running the application.
iisSettings setting will host iisExpress which in turn hosts the application and
starts a browser that hits the URL.
profiles setting will set the environment variables to development or production
(environmentVariables).
In IIS Express sub setting, launch variables can be set.
Note: We can use environment variable to load full CSS in development environment or
if it is production environment, we can load minified version of CSS.
BookListRazor will run the application as a command-line application. It will use
the internal web server Kestrel and starts a browser that hits the URL.
Note: The settings can also be set by going into the properties of the project under
‘Debug’ section.
Note: In order to test the settings, we can change the “IIS Express” setting present in
Standard toolbar to the respective setting and later test the application.
wwwroot
This folder consists of the static files in their respective sub folders css, js and lib
(Bootstrap and JQuery validation files).
Pages Folder
This is main folder inside any razor project.
It consists of all pages for our website.
It consists of a shared folder called ‘Shared’. They are partial views. Hence their
name precedes with an underscore.
Note: Partial pages are like user components. You can reuse them in multiple places in
your website.
_Layout.cshtml file is the default master page for your application. It consists
of header, body (div), footer and scripts that we want throughout the
application.
_ValidationScriptsPartial file consists of references to JQuery validation
functions.
_ViewImports.cshtml file consists of @addTagHelper directive that will
include [Link]. These will have global scope.
We can also include custom tag helpers into our application.
_ViewStart.cshtml file will consists of the master filename for our application.
[Link], [Link] and [Link] are actual razor pages (views). Each
file will their own respective (Page) model files (like [Link]).
Routing in Razor Pages
Routing in [Link] Razor Pages maps URL’s to physical file on disk.
Razor Pages needs a root folder.
[Link] is a default document.
URL Maps To
[Link] /Pages/[Link]
[Link]/index /Pages/[Link]
[Link]/account /Pages/[Link] (Initially searches here)
/Pages/account/[Link] (If not found, searches here)
Tag Helpers
Tag Helpers are introduced with .Net Core.
Tag Helpers enable server-side code to participate in creating and rendering HTML
elements in Razor files.
Tag Helpers are very focused around the HTML elements and much more natural to use.
Note: HTML Helpers are just methods throughout your Razor marker. They are present in
earlier versions of [Link] Core MVC.
There are few Tag Helpers in _Layout.cshtml file. They are listed below:
asp-area (It is present as part of the tag <a>)
asp-page: It is used to redirect to any of the razor pages (Also for <a> tag).
asp-append-version: It can take either true or false (It is present for <script> tag).
Similarly, we can set tag helpers for labels, forms and buttons.
@*-----HTML Helper-----*@
@[Link](“FirstName”, “FirstName : “, new { @class = “form-control” })
@*-----Tag Helper--------*@
<label class=”form-control” asp-for=”FirstName”></label>
@*-----HTML Helper-----*@
@[Link](m->[Link], new { @class = “col-md-2 control-label” })
@*-----Tag Helper--------*@
<label asp-for=”FirstName” class = “col-md-2 control-label”></label>
Note: HTML Helpers are not so user-friendly. Label uses asp-for tag helper.
The Main Method
Note: In classic [Link], code in the [Link] assembly took care of starting the
application.
[Link] file consists of methods in which you can write custom logic.
In [Link] Core, [Link] file will not be present. Startup is defined by you and that
starts with Program class file. It consists of Main method.
Main method is the entry point of the application.
Note: The application initially starts as a command-line application.
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
[Link](args)
.ConfigureWebHostDefaults(webBuilder =>
{
[Link]<Startup>();
});
}
Note: Configuration is done by calling CreateHostBuilder() method. It is a static method
that returns IHostBuilder. On that object, Build() and Run() is called. From that point
onwards, your application has become [Link] Core application.
CreateHostBuilder calls CreateDefaultBuilder on static WebHost class that configures the
WebHost using defaults.
It deals with the configuration on how [Link] Core deals with web server configuration
files, routing and so on.
You can see on the top of