programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Friday, February 27, 2015

Understanding controllers in MVC

Understanding controllers in MVC:

Controllers in MVC:

"In simple words, a controller is a contract/bridge between a model and the view.
Here is the flow:
A controller is used for main request processing logic. If a page has to talk with database, the controller sends a request to the model, model performs its task with db and returns some response or db records back to the controller then controller sends this response to the view"
As this type of question lend itself too many religiously answers, I believe that the is no "one way to rule them all". Now in the Monorail and ASP.NET MVC (and also Roar of course), a Controller is simply a collection of Actions. The correct question then is "What is the role of Action".

In book, the role of the Action is to separate the Domain Model from the presentation, both in terms of data structures, and in concerns. Everything that is specialized to the fact that the interface with the domain is through WEB requests, is the controller's layer responsibility. That includes data binding and transformations, dealing with Authentication (but not authorization), and making decisions for the view templates. So, an action will take parameters from the incoming request (a web is not a Domain concern), bind these to a meaningful data that can be send to the Domain as a Query or Command, in the Domain's language, without no cookies, FORM, QueryString, and other "web stuff". It would also, when viewing data, will transform the domain objects that got returned from the Model, into a View Model, that in the same book mentioned earlier is a model separated from the Domain model, and is in charge of supplying the view-template with all the data and the decision making it needs. So, for eg., the view should not ask if (view.User.IsAdmin) and render an "EDIT" button, but instead the Controller's action will have made this question, and supplied the view with a decision, for the view to ask if (view.ShouldRenderEditButton)
So, the Controllers layer separates WEB concerns from DOMAIN concerns. Related Other Post:

No comments:

Post a Comment