Responsibilities of the View

Asked

Viewed 83 times

6

Throughout the internet, I find posts warning about the responsibility of View that should only take care of its name and display the content.

Although MVC is based on exactly the distribution of functions and separation of the application by layers, I would like to understand the aggravating factors of using the View to perform some simple functions such as conditional.

Using the View thus, there is some loss of performance or security vulnerability?

For example, in one of my applications I receive traffic values from the URL (id) via a ActionLink and do a check on it for a conditional display of content. This would be a bad practice?

2 answers

3

In no way would it be bad practice View’s job is exactly this, display the data and these types of validations, which are more than normal, are required.

Regarding the security issue, no, because the page is written at once by Response and does not provide any access to the user.

3


Utilise for, foreach, if, switch, etc. are normal practices in ASP.NET in their Views. There is no performance loss and the security part is not affected, what the internet user has as a result in his browser is only HTML.

There is clear sense factor, I for example put most encodings in the Controller and go up to the Views only what is necessary. Example, if I send a @model being a List of some object (IEnumerable, IList, List, ICollection, etc.) I am obliged to make one for or foreach to show the data and this is quite normal in ASP.NET MVC applications.

In short, most of the programming Controller and in Views just make trivial codes, like a for, one if, i.e., the basic.

  • What about Where in lists? It’s right not to have this in View, right?

  • This @Diegozanardo is not good practice, already send the final information and in Views basic things!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.