What is MVC Framework?
Prem Prem
on
3/27/2024 4:37:07 PM
MVC Framework
The MVC architectural is most used development pattern in software engineering. All most all programming languages use MVC with slight variation, but conceptually it remains the same.
The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the view, and the controller.
Model View Controller (MVC)
MVC is used to decouple user-interface (view), data (model), and application logic (controller). This pattern helps to achieve separation of concerns.
Using the MVC pattern for websites, requests are routed to a
Controller that is responsible for working with the Model to perform actions and/or retrieve data.
The Controller chooses the View to display and provides it with the Model.
The View renders the final page, based on the data in the Model.
ASP.NET MVC framework
ASP.NET gives you a powerful, patterns-based way to build dynamic websites using the MVC pattern that enables a clean separation of concerns.
The ASP.NET MVC framework is a lightweight, highly testable presentation framework that (as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based authentication.
The MVC framework is defined in the System.Web.Mvc assembly.
MVC architecture supported in ASP.NET
MVC stands for Model, View, and Controller. MVC separates an application into three components - Model, View, and Controller.
Model:-
Model represents the shape of the data. A class in C# is used to describe a model. Model objects store data retrieved from the database.
Model represents the data.
Example:
public class Person
{
public int PersonId { get; set; }
[Required]
[MinLength(2)]
public string Name { get; set; }
[Phone]
public string PhoneNumber { get; set; }
[EmailAddress]
public string Email { get; set; }
}
View:
View in MVC is a user interface. View display model data to the user and also enables them to modify them. View in ASP.NET MVC is HTML, CSS, and some special syntax (Razor syntax) that makes it easy to communicate with the model and the controller.
View is the User Interface.
Example:
<table class="table">
<thread>
<tr>
<th>@Html.DisplayNameFor(model=>model.Name)</th>
<th>@Html.DisplayNameFor(model=>model.PhoneNumber)</th>
<th>@Html.DisplayNameFor(model=>model.Email</th>
</tr>
</thread>
<tbody>
@foreachf(var item in Model)
{
<tr>
<td>@Html.DisplayFor(ModelItem=>item.Name)</td>
<td>@Html.DisplayFor(ModelItem=>item.PhoneNumber)</td>
<td>@Html.DisplayFor(ModelItem=>item.Email)</td>
</tr>
}
</tbody>
</table>
Controller:
The controller handles the user request. Typically, the user uses the view and raises an HTTP request, which will be handled by the controller.
The controller processes the request and returns the appropriate view as a response.
Controller is the request handler.
Example:
public class PeopleController : Controller
{
private readonly DBContext _context;
public PeopleController(DBContext context)
{
_context = context;
}
// GET: /people
public async Task Index()
{
return View(await _context.People.ToListAsync());
}
}
0 Comments on this post
Comments(0)||Login to Comments
- see more..
Categories
ALLAsp.Net (3)
Sitecore (11)
Issues Resolved (9)
Sitecore 9.3 (2)
International Business (1)
Innovations in Industries (3)
Supply Chain Management (1)
Industrial Engineering (14)
Sitecore 10 (4)
Sharepoint (1)
Azure (4)
Cloud Computing (1)
Online Courses (1)
Online Resources (2)
C# (1)
Blazor WebAssembly (2)
Sitecore form (1)
MS Sql Server (1)
Angular 11 (2)
Automobile Engineering (5)
Sitecore powershell (1)
Devops (2)
Microservice Architecture (1)
Sitecore Interview Questions (2)
Dotnet interview questions (1)
Sitecore useful links (1)
Privacy&Cookies (2)
Solr Search (2)
JavaScript (1)
sitecore xm cloud (3)