Saturday, August 17, 2013

MVC Controller

MVC Controller

A controller is responsible for controlling the way that a user interacts with an MVC application.
                
A controller determines what response to send back to a user when a user makes a browser request.

·         It is Just a class that implements IController

·         Use the View Method to display the View.

·         Public methods are the action methods

Explanation: In MVC, we write the code in service oriented pattern. Anything you write as service oriented, every method you write in controller should be public, globally accessed because we will have multiple layers.


·         Apply [NonAction] attribute to turn this off
Explanation:
[NonAction]
Public void Add ()
This method will be public to your project, but not accessible to other project.



·         Invoking via routing mechanisms(**********)
Explanation: MVC says we will have friendly Uri
Uri—uniform resource identifier
Today it is not URL, today they are URI



What is routing:
Is the process where requested URL is mapped to MVC Controller method resulting in the simple URL’S to invoke methods
Aspx request—handler->aspx engine
Webserveràhandleràextensions
Webserver are based on handler and handlers are based on extensions
Routing will do the mapping to webserver understandable format.

How mapping is performed
Based on routing instructions that the developers provide .
In every mvc project ,that we create by default following route instructions is added
Note: By default one route instruction is added.

Where is the route mapping code written?

The route mapping code is written in the “global.asax” file.


Why Routing Instructions
Because mvc works with routing, so we have one routing instruction by default.
Local hostà routing
Is the mediator between webserver handler and URL

For example, consider the following URL:  /Job/Details/3
• This URL is parsed into three parts like this:
Controller = Job Controller
Action = Details & Id = 3
The default route includes default values for all three segments. The default Controller is Home Controller,
The default Action is Index,
And the default Id is an empty string.

Controllers
Core Action Functionality

What are the different types of results in MVC?

In MVC, we will not have the return types as string, int, etc.

Actions methods should return an Action Result
• ViewResult if you want to show a View
• ContentResult directly returning content
• RedirectResult to redirect to a new URL
• RedirectToRouteResult redirect to route
• EmptyResult null object pattern
• JsonResult returning a Json
JavaScriptResult - script that can be executed on the client

--------------------------------------------------------------------------------------------------------
1.    FileContentResult - Returns a file to the client
2.    FileStreamResult - Returns a file to the client, which is provided by a Stream
3.    FilePathResult - Returns a file to the client


No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...