1.

Can you explain Model, View, and Controller in MVC?

Answer»

MVC ARCHITECTURE represents the domain-specific data and business logic. It maintains the data of the application, model data hold the data in public property.

We can also manipulate the data in the business logic layer

Namespace mvc.Models {    public class Student {    public int StudentId { get; set; }    public string StudentName { get; set; }    public int Age { get; set; } } }

In Model, we can apply validation to the property using Data Annotation instead of APPLYING on the client side. For adding data Annotation we need to add the reference “System.ComponentModel.DataAnnotations ASSEMBLY

Like we apply on StudentId

Eg. 

[Display(Name=”StudentId ”)] [Required(ErrorMessage=”StudentId is Required”)] Public int StudenId {get;set;}

View : View is the User Interface where The user can display its own data and can modify its data, In this, the data is passed from the model to the view. The view has a different folder with the same name as of controller and has different views in it of different actions.

There are 3 types of Views in MVC

  • User View : To create this view use page template. The inherited class name will be available in <%@ page directive with inherits attributes.
  • Master Page View : To create a master page view we use a template known as “MVC2 view master page.it have a default extension of.master.
  • Partial View : Partial View is the same as UserController in asp.net it is inherited from the System.Web.Mvc

Controller: It is the most essential part of the MVC in asp.net since it is the FIRST recipient which INTERACTS with HTTP and finds the model and actions. So it is the controller which decides which model should be selected and how to carry the data from the respective view, a controller is inherited from the System.Mvc.Controller. The routing map of the controller is decided in RouteConfig.cs which is under App Start Folder.

Eg, http://localhost:61465/Employee/Mark

Where Employee is a controller name and mark is the action.



Discussion

No Comment Found