MVC

Shivani Nalawade
4 min readMay 18, 2020

--

MVC architecture

Model View Controller or MVC as it is popularly called, software architecture pattern for developing web applications. A Model View Controller pattern is made up of the following three parts −

  1. Model
  2. View
  3. Controller

Model :

  • It is the lowest level of the pattern responsible for maintaining data.
  • Model represents domain specific data and business logic in MVC architecture.
  • It maintains the data of the application.

The model is responsible for managing application data. It responds to the request from view and to the instructions from controller to update itself.

Model folder in MVC folder structure:

Right click on Model folder -> Add -> click on Class.

  1. In the Add New Item dialog box, enter class name ‘Student’ and click Add.

View :

  • View is a user interface. View displays data from the model to the user and also enables them to modify the data.
  • A presentation of data in a particular format, send by the controller’s decision to present the data.

View folder in MVC folder structure :

  1. MVC views are stored in Views folder. Different action methods of a single controller class can render different views, so the Views folder contains a separate folder for each controller with the same name as controller
  2. From StudentController, will resides in Views > Student folder as shown below.
  • If you want to Create New View, We have already created StudentController and Student model in the previous section. Now, let’s create a Student view and understand how to use model into view.

open a StudentController class -> right click inside Index method -> click Add View.

Controller :

  • The Controller in MVC architecture handles any incoming URL request.
  • A Controller class name must end with “Controller”.
  • Controller is a class, derived from the base class . Controller class contains public methods called Action methods.
  • Controller and its action method handles incoming browser requests, retrieves necessary model data and returns appropriate responses.

for example; controller for home page must be HomeController and controller for student must be StudentController.

Adding a New Controller :

  • Now, let’s add a new empty controller in our MVC application in Visual Studio.
  • Here, we will create a new StudentController.

Controller in MVC folder structure :

  1. In the Visual Studio, right click on the Controller folder -> select Add -> click on Controller.
Add new controller
Adding Controller

SSL :

The importance of SSL Certificate

Secure Sockets Layer (SSL) is the standard security technology for establishing an encrypted link between a web server and a browser.

This link ensures that all data passed between the web server and browsers remain private.

For SSL connection a web server requires a SSL certificate. Your web server creates two cryptographic keys, a Private Key and a Public Key.

.NET SDK :

NET Framework SDK, are software development kits (SDK) from Microsoft.

The .NET Core SDK is a set of libraries , documentation, header files, and tools that allow developers to create .NET Core applications and libraries.

It contains the following components that are used to build and run applications:

  • The .NET Core CLI.
  • .NET Core libraries and runtime.

.NET Core CLI :

The . NET Core command-line interface (CLI) is a cross-platform for developing, building, running, and publishing . NET Core applications.

The .NET Core CLI is installed with .NET Core SDK for selected platforms. So we don’t need to install it separately on the development machine.

We can verify whether the CLI is installed properly by opening command prompt in Windows and writing dotnet and pressing Enter.

.NET Core Command-line Interface

What is dotnet new?

The dotnet new command creates a . NET Core project or other artifacts based on a template.

.NET core releases various versions such as new in .NET Core 2.0, new in .NET Core 2.1 , new in .NET Core 2.2 , new in .NET Core 3.0 , new in .NET Core 3.1 etc.

now we learn latest version of new in .NET Core 3.1 .One of the biggest enhancements is support for Windows desktop applications (Windows only).

By using the .NET Core 3.0 SDK component Windows Desktop, you can port your Windows Forms and Windows Presentation Foundation (WPF) applications.

Where WPF is used to build Windows client applications that run on Windows operating system.

The dotnet run :

The dotnet run command provides a convenient option to run a application from the source code with one command.

The dotnet build :

The dotnet build command builds the project and its dependencies into a set of binaries.

dotnet build will only build the project without actually running it.

I hope this guide has been helpful for you.

--

--

No responses yet