articles

Home / DeveloperSection / Articles / MVC(Model View Controller)

MVC(Model View Controller)

Manish Kumar1906 13-Jan-2017
Model

Model is used to work with application data it is responsible for maintaining application data and business logic. Model Class is kept in the model folder.Model notifies a view for changes(view get data from model).It represents a set of classes that represents the business logic.It is responsible for providing all the business logic and validation to the view.basically model class include public property which will be used by application for manipulating the data.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace MvcApplication2.Models
{
    publicclassClass1
    {
        publicString Name { get; set; }
        publicString Address { get; set; }
        publicString Email { get; set; }
    }
}

View

View is the presentation layer of our project.The view is only responsible for only displaying the data and data is received from the controller as the result. The view is defaultly stored in the view folder.in the view basically we use .cshtml file where we write c# or vb code. When we create view it something look like this and view is binded through model 

@model MvcApplication2.Models.Class1@{
    Layout = null;
}
 
<!DOCTYPEhtml>
 
<html>
<head>
    <metaname="viewport"content="width=device-width"/>
    <title>Index</title>
</head>
<body>
    <div>
        <h1>Welcome to the index view</h1>
    </div>
</body>
</html>

Controller


It act as a mediator between view and model and is responsible for controlling the application logic .It send commands to the model to update the model it can also commands to its associated view to change the view.Controller receives input from the view.then process user data with the help of model and passing the results back to the view.it is responsible for controlling the way that a user intracts.it is responsible for what data to be send to user when user  request.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
 
namespace MvcApplication2.Controllers
{
    publicclassDefault1Controller : Controller
    {
        //
        // GET: /Default1/
 
        publicActionResult Index()
        {
            return View();
        }
        publicActionResult About()
        {
            return View();
        }
 
    }
}



here this is default controller inheriting controller base class.it has two method


Index() and About(). with respective view.



Updated 30-Jan-2019

Leave Comment

Comments

Liked By