asp.net-mvcmodel-view-controllerpresentation-layer

MVC: calculation of UI elements in Controller or View?


I am working on an ASP.Net MVC application, and its architecture consists of the usual DAL, BL, and PL layers.

Addresses are stored as separate fields in the database, but shall be displayed in a single field in the UI.

When it comes to displaying, I need to handle various optional fields (e.g. state, country, several lines for the address).

My question: should this calculation of the effective display string be handled by the controller or by the view? Does the MVC paradigm offer some rules or recommendations for this question?


Solution

  • Your controller shouldn't know anything about how the addresses are displayed - since you might have different views that call into the same controller action that want to render the address differently. It is the concern of your view as to how the address is rendered for a particular purpose