You are on page 1of 3

MVC:

1.MVC has major modules

MVC :

Model View controller

Model is business object model, we will create properties

controller - is for backend validation an updating the database - Data layer.

View is responsible for rendering the HTML page (front end)

We use Razor template to render HTML.

Razor template is MVC engine , used to create dynamic web pages.

It starts with @Symbol

How will send data from front end to back end?

we can use Model ,

If we want transfer from back end to front end we use view back.

2.Advantages of MVC

- Loosely coupled
- Light weight
- Re usabilty
- More understandable

3. MVC Application Life cycle

Any web application has two major steps


- Understanding the request and based on the type of request, sending out the
response

1.Creating the request - Request object creation has four major parts

a.Fill route:

MVC request are mapped to route tables which specifiies which controller and action
to be invoked.
So first thing is to fill out the route table with route collection. Filling of
route table happens in
global.asax file.

b.Fetch Route

Depending on the URL sent "URLRoutingModule" search the route table to create
"RouteData" object which has the details of
which controller and action to invoke.

c.Request Context created:


"Route Data" objects creates the "Request Context" object

d. Controller instance created:


Request object is sent to "MVCHandler" instance to create control class instance.
Once the controller class object is created it calls the "execute" method of the
controller class.

2.Create Response Object:

This has two steps - Executing the action and sending the results to the view

4.Different return type of controller action method

Total there are 9 returns type which return results from controller to view.

Base type of all these result type is ActionResult

1.ViewResult(view) : this return type is used to return a webpage from a action


method

2.PartialViewResult(partial) : this return type is used to return the part of the


view that is rendered in another view.

3.RidrectResult(redirect): this return type is used redirect to any other


controller or action method depend on the URL

4.RedirecttoRouteResult: this return type is used when we want to direct to any


other action method

5.ContentType: this result type is used to retun any httpContent like text /plain
as the result of action

6.JSON Result: this return type is used when we want to return any json messages

7.Javascript result: this return type is used when we want to return the java
script that returns in the browser

8.File results: this can be used when we want to send binary output in response.

9.empty reslut: this return type is used when we return nothing (void ) in the
result

5. Filters in MVC

In MVC controller defince action method, usually these action methods generally
have a one to one relationship with UI controls such as clikcing button or link.
But many times, we would like perfom some action before and after some operation.
For achieving this functionality, MVC provides feature called filters.

Types of Filter:

1.Action Filters: Action filters are used to implemnet logic that gets executed
before and after control action executes.

2.Authorization Filters: this is used to implement authication and authorization of


control action
3.Result Filter: This is used to implement logic that is implemented before and
after view result is executed.

4.Exception Filter: this filter is used to handle errors raised by either your
control actions or control action methods

6.Routing in MVC

Routing is mechanisum that process incomming URL and give the desired response.

There are two type routing

1.Convention based routing: To define this type of routing, we call MapRoute method
and set its unique name, URL pattern and specify some default values

2.Attribute based routing: in this method, we specify the route attribute in the
action method of controller

Routing is URL pattern that is mapped to handler to handle incoming request.

There are 3 segments in the routing

1.Controller Name
2.Action Method name
3.Parameter

7. Ways of passing/stroing data between Controller and View

1.View Data - It is used to pass data from controller to view, It requires type
casting for large data and check for null value to avoid error

2.View Bag

3.Temp Data

You might also like