View's Responsibilities

6

Throughout the internet, I find posts warning you of the responsibility of View who should only watch over your name and display content.

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

Using View in this way, is there any performance loss or security vulnerability?

For example, in one of my applications I get trafficked values from the URL (id) via a ActionLink and check the content for a conditional view of content. Is this a bad practice?

    
asked by anonymous 23.08.2014 / 13:26

2 answers

3

Use for, foreach, if, switch, etc. are typical practices in ASP.NET in their Views . There is no loss of performance and the security part is not affected, what the internet user results in your browser is only only HTML .

The sense factor is clear, for example, I put most encodings in Controller and upload to Views only as necessary. If I send a @model being a List of some object ( IEnumerable , IList , List , ICollection , etc.) I'm forced to for or foreach to show the data and this is pretty normal in ASP.NET MVC applications.

In short, most programming does in Controller and in Views only make trivial codes, such as for , if , ie the basic .

    
23.08.2014 / 16:31
3

In no way would it be bad practice for the View to do exactly that, display the data, and these types of validations, which are more than normal, are needed.

As for the security issue, the page is written all at once by Response and does not provide any access to the user.

    
23.08.2014 / 15:38