When should you use strongly typed views?

I enjoy the lack of “magic lines” in my views and controllers, but are there any deviations from this approach?

It seems not. I read blog entries here and there meaning differently.

+3
source share
3 answers

Extending models, as a last resort, to model-on-action, to support additional presentation properties that may not be directly related to the data model. For example, if your presentation differs depending on the role, you need to create a new model to encapsulate the data model and the parameters associated with the roles. The same effect can be achieved using the data model as a presentation model and adding several parameters to the ViewData through the "magic lines".

EDIT . This is not a reason to "avoid" strongly typed representations, but to give some balance of choice when you need to create a new model taking into account the view, and not use the existing model and expand it has ViewData properties.

+8

, , , . , , , . . , .

+1

As far as I know, there is no single drawback of strongly typed representations. I do not understand why magic lines and an anonymous object are in any case part of the MVC framework. I try to avoid them all. You don't want to pass arguments to the type object in the rest of the code, so why do you need to do this in the user interface?

+1
source

Source: https://habr.com/ru/post/1703772/


All Articles