Here is a complete guide for beginners to learn ASP.NET MVC. In this series, we will go through the following points.
- Prerequisites to learn ASP.NET MVC
- Difference between ASP.NET Web Form and Asp.Net MVC
- Why choose AS{P.NET MVC?
- Overview of Model
- Overview of View
- Overview of Controller
- The configuration file of ASP.NET MVC
Prerequisite to learn ASP.NET MVC
Understanding of HTML - Reader/Learner should know the basic structure of HTML file and understanding of tags of HTML.
Understanding of CSS - Reader/Learn should have the basic understanding of CSS writing and properties of CSS.
Understanding of Web Terminology - Following basic activities of web terminology :
- Round Trip
- Web Server
- Session
- Developer Tools
- HTTP Request
- HTTP GET / HTTP POST
Difference between Asp.Net Web Form and ASP.NET MVC
| SR.NO. | AS{P.NETWebForm | ASP.NETMVC |
| 1 | Asp.net web form having event basis programming. | ASP.NETMVC not having server-side event basis programming. Clientside event you can work out. |
| 2 | ASP.NETweb form having server-side controls | AS{P.NETMVC having HTML helper. |
| 3 | ViewState for client side state management. | ViewState not available in Asp.net MVC. |
| 4 | ASP.NETweb form application pages divided into two parts ASPX and ASPX.CS page. | ASP.NETMVC application pages divided into three part Model, View, and Controllers. |
| 5 | As per URL basis ASPX file compulsory on the server. | As per URL basis controller should have ActionMethod in the controller. |
| 6 | For a consistent look, master pages are used in web form. | For a consistent look, layout view is used in MVC. |
There is a lot of changes in the web form and MVC you will come to know or you will observe the changes while you start working on ASP.NET MVC.
Why choose Asp.Net MVC?
MVC (Model View Controller) having followings features :
- SEO friendly very descriptive URL you can design.
- Fully customize routing solution.
- WebForm page very heavy in weight but MVC is very lightweight.
- Separation of concerns.
- Test Driven Development.
- Faster comparatively AS{P.NET WebForm
- You can design Single Page Application very efficiently.
- You can use the power of React, Angular, and other javascript frameworks very easily.
- Freedom to choose view engine as per your requirement.
- No heavy server-side controls.
- Freedom to create customized HTML helper and its functionality.

(Image taken from https://msdn.microsoft.com/en-us/library/dd381412(v=vs.108).aspx)
Overview of Model
Model is a simple class which created as per business logic or form requirement or database table. The model having simple public properties and model class file stored in a MODEL folder of ASP.NET MVC project structure.
Basically, there are two types of models
- Model or Domain Model
- ViewModel
We use a model in MVC framework for followings
- To receive input/data from the user.
- Data validation terminology or restriction or validation can define in model.
- Transfer data to Table / Collection.
- To display data from table/collection and return to view.
ViewModel
As its name defines itself, ViewModel is mostly used to display joined data from various tables or very complex business summary or form. In short, ViewModel is a mixture of models to display information/data.
Difference between Model and ViewModel is that we use Model (Domain Model) for all the purposes and ViewModel only used to pick the data and handover to view.
Example Model
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace MvcPractice.Models
- {
- public class MemberModel
- {
- //Properties for Member ID get and set
- public int MemberID { get; set; }
- //Properties for Member Name get and set
- public string MemberName { get; set;}
- //Properties for Member Full Address get and set
- public string MemberAddress { get; set; }
- //Properties for Member City get and set
- public string MemberCity { get; set; }
- //Properties for Member Phone get and set
- public int MemberPhone { get;set }
- //Properties for Member Married Yes / No get and set
- public bool IsMarried { get; set; }
- //Properties for Membership Fees get and set
- public decimal MemberFees { get; set; }
- }
- }
Other Model Example with Related to ViewModel Example.
Example Model1
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace MvcPractice.Models
- {
- public class StudentModel
- {
- public int StudentID { get; set; }
- public string StandardID { get; set; }
- public string StudentName { get; set; }
- }
- }
Example Model2
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace MvcPractice.Models
- {
- public class SubjectModel
- {
- public int SubjectID { get; set; }
- public int SubjectName { get; set; }
- }
- }
On above models, ViewModel has been created.
Example ViewModel
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace MvcPractice.Models
- {
- public class StudentViewModel
- {
- public int StudentID { get; set; }
- public string StandardID { get; set; }
- public string StudentName { get; set; }
- public List<SubjectModel> SubjectList { get; set; }
- }
- }
In above ViewModel example, you can see that SubjectModel is used in StudentViewModel. Why that is used is to display subject list of that student.
Overview of Controller
The Controller is the heart of MVC framework. First, the request comes to or knocks to controller and controller’s action method. The controller is also a simple class but inherited from Controller class. This class is a part or member of System.Web.Mvc namespace. The Controller reads and handles query string process at the same time.
Controller functionality
URL : www.saischool.com/student/index
| URL | URL Description |
| www.saischool.com/ | Domain Name |
| student/ | Controller Name |
| index | Action Method |
In following image and code of StudentController you can see following methods,
- Index
- Details
- Create
StudentController.cs Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace MvcPractice.Controllers
- {
- public class StudentController : Controller
- {
- // GET: Student
- public ActionResult Index()
- {
- return View();
- }
- // GET: Student/Details/5
- public ActionResult Details(int id)
- {
- return View();
- }
- // GET: Student/Create
- public ActionResult Create()
- {
- return View();
- }
- // POST: Student/Create
- [HttpPost]
- public ActionResult Create(FormCollection collection)
- {
- try
- {
- // TODO: Add insert logic here
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- // GET: Student/Edit/5
- public ActionResult Edit(int id)
- {
- return View();
- }
- // POST: Student/Edit/5
- [HttpPost]
- public ActionResult Edit(int id, FormCollection collection)
- {
- try
- {
- // TODO: Add update logic here
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- // GET: Student/Delete/5
- public ActionResult Delete(int id)
- {
- return View();
- }
- // POST: Student/Delete/5
- [HttpPost]
- public ActionResult Delete(int id, FormCollection collection)
- {
- try
- {
- // TODO: Add delete logic here
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- }
- }

Rafnas T PPosted Mar 19, 2018, 9:13 AM
Thank you for such a nice explanation.
Arvind SinghPosted Mar 19, 2018, 4:27 AM
Good approach keep it up..........