Introduction to ASP.NET Core MVC

Introduction to ASP.NET Core MVC

ASP.NET Core MVC is Microsoft’s Web Application development framework that is in great demand today. It is based on Model-View-Controller (MVC) architecture, ideas and techniques from Agile Development, and the best parts of .NET platform. In this tutorial I will introduce you with ASP.NET Core MVC.

History of ASP.NET Core MVC

Microsoft released ASP.NET Core MVC during the latter half of 2015. Over the past 3 years they have added new features to this framework making it more powerful. The current version of this platform as on today is 2.0 version. This tutorial series will teach you all the features of ASP.NET Core MVC so that you can create any sort of web application by your own.

Features of ASP.NET Core MVC

This framework is bundled with some of the most amazing feature. These are:

It is Open Source

You are free to download this framework’s source code from https://github.com/aspnet and even modify and compile your own version of it.

Cross-Platform

ASP.NET Core MVC is cross-platform both for development & deployment. It is available for all operating systems – Windows, Linux & macOS.

You can do development works in ASP.NET Core MVC using Visual Studio editor by Microsoft. Visual Studio works only on Windows & macOS.

For Linux, use Visual Studio Code editor.

Full Control over HTML & HTTP

In ASP.NET Core MVC you get full control over HTML. You can create, simple to complex type, HTML styled with CSS and display them on the browser.

Similarly you get full control over HTTP requests passed between the browser and server. Creating AJAX request is also very easy.

You can easily use client side libraries like jQuery, Angular, React & Bootstrap with ASP.NET Core MVC.

Extensible Framework

ASP.NET Core MVC is highly extensible. You can make applications that can be extended to any levels in future. Key features of this framework that gives it the extensible power are:

1. View Components
2. Tag Helpers
3. Routing

You will learn about all these features later on.

Testing made Maintainability

The ASP.NET Core MVC architecture is great for making your application maintainable and testable. You can separate, different areas of your application, into independent pieces and test them independently. Testing frameworks like xUnit & MOQ can be easily integrated for simulating any scenario.

ASP.NET Core MVC makes large to very large applications easy for maintaining.

Routing

ASP.NET Core MVC “Routing” makes SEO friendly URL which are easy to make and can be controlled from a single place. This removes the probability of error.

You don’t have to hard core the URL, instead the Routing will make it for you based on the structure which you have set.

Example of a SEO friendly URL is:

/women-clothing/skirts/

API

ASP.NET Core MVC APIs can take full advantage of language and runtime innovations familiar to C# programmers, like the await keyword, extension methods, lambda expressions, anonymous and dynamic types, and Language Integrated Query (LINQ).

Installing .NET SDK

To build your apps install .NET SDK which can be downloaded from here.

Installing Visual Studio 2017

The codes on these series of tutorials require installation of Visual Studio 2017 (VS 2017), Community Edition on your PC. VS 2017 requires Windows 8.1, 10 or higher version. It can also be installed on macOS.

For linux systems install Visual Studio Code.

The download link of VS 2017 is here- Download Visual Studio 2017.

Note – When installing VS 2017 you should select the option that says – .NET Core cross-platform development.

dot net core cross-platform development

MVC Architecture

The MVC Architecture is what ASP.NET Core is made from. MVC stands for Model-View-Controller, which are its 3 pieces.

  • Model – It contains the data which the application works with. This data is filled to the Model from the database or any other repository.
  • View – View forms the UI and is rendered on the browser. Views contains HTML layouts which the user actually sees on the browser
  • Controller – Controller is the brain of the MVC application. It processes the incoming request to the application, performs operations like data filling, data update, data delete, data inserts on the model, and finally renders an appropriate view to the browser based on the request.

mvc architecture

There can be multiple Models, Controllers and Views in a MVC application.

Understanding Models

Taking an example of a social community website like Facebook, a Model will contains all your details like – your name, ages, status, work info, your posts by date, your comments done on other profiles, your messages to other people, your liked pages and so on.

These details (your data) are filled on the Model by the Controller.

Models also help in preserving the business logic of the application (here for Facebook). For example when running paid ads in Facebook, Models will not allowed you to add invalid amounts on the ads. Example – ‘some amount’, ‘thirty’, ‘hello’ etc. It will also only proper amounts like ‘$10’, ’£20.50’, ‘$100’, etc

Models communicate with only Controllers and not with Views.

Understanding Views

Views are the User Interface (UI) in MVC and are rendered on the browser. They can contain static HTML or dynamic HTML sent by the Controller. Views communicate only with the Controllers and not with Models.

Controller is responsible for rendering a particular View based on the request it gets from the browser.

Understanding Controllers

Controller is the main thing in MVC. It sits between the View and the Model and communicates with them. All HTTP requests are received by the Controller, which after processing it, fills the data on the Model and sends the data on the View. The View is then rendered on the browser.

Controller contains simple to complex logic based on the working of the application.

Summary

I hope this introduction of ASP.NET Core MVC has taught you some good things about this excellent framework. The coming tutorial will take you direct to the coding.

Share this article -

yogihosting

ABOUT THE AUTHOR

This article has been written by the Technical Staff of YogiHosting. Check out other articles on "ASP.NET Core, jQuery, EF Core, SEO, jQuery, HTML" and more.