Learn C#.NET, ASP.NET MVC 5,ASP.NET Core that you can increase your knowledge and coding to develop the real-time project.

Sunday, March 24, 2019

Introduction to ASP.NET MVC

We will learn the introduction of ASP.NET MVC and advantages using ASP.NET MVC in this article.

MVC is an architectural design pattern which is used to develop the user interfaces. which will be maintainable, reusable, testable. It is used for separation of concerns.

MVC stands for Model, View, and Controller. MVC separates the application into three component like Model, View, and Controller. We will learn in detail what is Model, View, and Controller.

What is the design pattern?

A design pattern is a solution to the problems that occur in software development.
Design pattern helps us in applications development to resolve problems easily.

Example of design pattern 
  • MVC
  • Proxy
  • Singleton
  • Iterator
  • DAO 

What is ASP.NET MVC:

ASP.NET MVC is a web framework from Microsoft which is used to develop the web application. ASP.NET MVC use MVC architecture pattern. 
ASP.NET MVC are introduced in 2009 by Microsoft.

Advantages of using ASP.NET MVC

  1. Separation of code:

  • This feature is specified separating presentation logic from the database related logic. Easy to develop and modify using this feature.
  • In MVC based application the development process is split into three modules like Model - View - Controller.

2. Loosely coupling:
  • Loosely coupling represents less dependency.
  • Views is mvc are less dependency on models.
  • We can easily edit, expand and enhance the application.

3. Parallel Development:
  • This feature specifies developing models and views parallel.
  • It means multiple programmers work parallel on views and models.
  • This feature makes your application development is faster and easier.

4. Easy to perform unit testing:
  • Unit testing is the concept of testing only a certain portion of the application which is modified.
  • In MVC based application, we can easily perform unit testing.

5. TDD(Test Driven Development):
  • In TDD testers will guide by the development process.
  • MVC application is more comfortable for TDD because It will easy to modify at any point of time and any module.
  • TDD is one of the latest development process using in real time projects.

Model is a normal C# class.
Model is responsible to handle data and business logic.
A model represents the shape of the data.
Model is responsible for handling database related changes.

Sample code of model as follow:
namespace MVCDemo.Models

    public class Employee

        public int EmpId { get; set; }

        public string Name { get; set; }

        public string Email { get; set; }

        public double Salary { get; set; }

A view is responsible for UI(user interface).
View displays the data coming from the model.
A view is an HTML template which will be binding and displaying HTML controls with data.
The “.cshtml” file use the Razor view engine. And .cshtml views are use C# programming.
The view contains the following extension depends on languages.
1. .aspx
2. .asp
3. .html
4. .cshtml
5. .vbhtml
Following are the types of view in ASP.NET MVC -5
1. Layout View
2. Partial view
3. Normal view

A controller can contain action and non-action method. It is used to handle the user request coming from the browser. It will check the request from the browser and identify the action method and return the respective view.
A controller is inherited from “ControllerBase” class which is inside the “System.Web.Mvc” namespace.
While creating controller remember it always suffix as “Controller” keyword. Default Controller is “HomeController” and “Index” view.

Sample code of Controller as follow:
namespace MVCDemo.Controllers
    public class HomeController : Controller
       // GET: Home
        public ActionResult Index()
            return View();

Following is the diagram of ASP.NET MVC
what is ASP.NET MVC
                                             Fig. ASP.NET MVC Architecture
                                      Fig. ASP.NET MVC Architecture

As per the above figure, user request enters the URL on the browser the given request go to the server and call the routing which will execute the appropriate controller. And based on request controller execute the appropriate controller action method. It will pass the request to model if the controller action method has data from the database. After completing this request, the controller returns the response to the user.


Post a Comment

Upcoming Articles/Videos

Design Pattern
SOLID Design Principles
Copyright © Programming With Shri | Powered by Shrimant Telgave Home | Disclaimer | Privacy Policy | Terms and Conditions Design by Shrimant Telgave