0% found this document useful (0 votes)
203 views

Complete Guide To ASP - Net Core MVC 3.1

Uploaded by

DolaDamaKrishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
203 views

Complete Guide To ASP - Net Core MVC 3.1

Uploaded by

DolaDamaKrishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Complete guide to ASP.Net 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

Bulkybook.azurewebsites.net

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: Visualstudio.microsoft.com/downloads/vs/

Download Visual Studio -> Community 2019

Note: In Visual Studio 2017, .Net Core 3.1 will not work.

 dotnet.microsoft.com/download/dotnet-core/3.1

Windows (OS) – x64 (Installers)

 microsoft.com/en-us/sql-server/sql-server/downloads

Developer – Download now (Free)


 docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-
ssms?view=sql-server-ver15

Bhrugen.com

 Introduction to Dapper (.NET 5)


 Introduction to ASP.NET Core MVC (.NET 5)

Evolution of ASP.Net Core

 ASP – 1996
 ASP.Net Webform – 2002
 ASP.Net MVC – 2009
 ASP.Net Core – 2016
 ASP.Net Core 2 – 2017
 ASP.Net Core 3, 3.1 – 2019 Q4

Razor Project
Visual Studio 2019 -> Create a new project

ASP.Net Core Web Application > Next

Project Name (BookListRazor)

Create a new ASP.Net Core Web Application (.Net Core/.Net Framework) (ASP.Net 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 ASP.Net Core 2.0.
o Razor Pages is a new feature of ASP.Net 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: index.cshtml is treated as Razor View or UI of Razor Pages, whereas index.cshtml.cs


is not code-behind file. It is Page Model.

Note: index.cshtml.cs consists of OnGet() handler is present. It is like controller action


method.
Note: ASP.NET Core 1.0 does not create .csproj file, instead, it uses .xproj and
project.json files to manage the project. This has changed in ASP.NET 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 > Newtonsoft.json (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 BookListRazor.csproj file.

Where is the Meta Package?

Microsoft.AspNetCore.App 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 > LaunchSettings.json – 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 Microsoft.AspNetCore.Mvc.TagHelpers. 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.
Error.cshtml, Index.cshtml and Privacy.cshtml are actual razor pages (views). Each
file will their own respective (Page) model files (like Index.cshtml.cs).

Routing in Razor Pages


Routing in ASP.Net Razor Pages maps URL’s to physical file on disk.

Razor Pages needs a root folder.

Index.cshtml is a default document.

URL Maps To

www.domain.com /Pages/Index.cshtml

www.domain.com/index /Pages/Index.cshtml

www.domain.com/account /Pages/account.cshtml (Initially searches here)

/Pages/account/index.cshtml (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 ASP.Net 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-----*@

@Html.Label(“FirstName”, “FirstName : “, new { @class = “form-control” })

@*-----Tag Helper--------*@

<label class=”form-control” asp-for=”FirstName”></label>

@*-----HTML Helper-----*@

@Html.LabelFor(m->m.FirstName, 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 ASP.Net, code in the System.Web assembly took care of starting the
application.

Global.asax file consists of methods in which you can write custom logic.

In ASP.Net Core, Global.asax 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) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<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 ASP.Net Core application.

CreateHostBuilder calls CreateDefaultBuilder on static WebHost class that configures the


WebHost using defaults.

It deals with the configuration on how ASP.Net Core deals with web server configuration
files, routing and so on.

You can see on the top of

You might also like