Controller storage and viewing separately with highly typed objects

I have a question about how to keep the controller and view separately. It seems to me that the controller should only pass the model to the view, and the view decides how to display the model. Thus, the controller and model remain separate and can be independently developed. However, many tutorials that I see on the Internet and even in the Pro ASP.NET MVC Framework book, I see many examples using either ViewData ["string"] or TempData ["string"].

Doesn't that lead to two problems? The first is that the view is now somewhat related to the controller, since it needs to know the name of the rows that the controller sets in ViewData / TempData. Secondly, they are poorly printed, which means the absence of Intellisense. If I were developing a controller, I could not just tell another developer working on the view to just use Intellisense for the model, I would have to give it the name of the lines, and if I ever change the names of the lines, I'd also need to change him in the submission.

I think in the end what I ask is right? Or am I not understanding something?

+3
source share
3 answers

View Data - , , , . ViewModel. . Scott Gu NerdDinner ( ) , ViewModel ViewDate vs ViewModel.

, .

+4

, , . , , , .

:

  • ViewModel
  • , ViewModel

Auto-Mapper, . Model ViewModel.

+2

, , , ViewModel, / . ViewModel , , , .

+1

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


All Articles