Why not to use ViewBag heavily?

后端 未结 3 1208
情话喂你
情话喂你 2021-01-15 03:43

What if i use too many ViewBag in MVC3 page? What extreme problems will be there if i continue use them heavily. In less words, what are the disadvantages of ViewBag and wha

相关标签:
3条回答
  • 2021-01-15 04:06

    what is the alternate for it?

    You should only use ViewModels, It's the recommended approach. Create Strongly typed views. It would make your code cleaner and easy to maintain.

    What extreme problems will be there?

    Issue with Viewbags/ViewData is compile time checking. ViewBags are just dictionaries and you won't be aware about any issues until run time and thus it makes your code error-prone. So always try to go with ViewModels.

    0 讨论(0)
  • 2021-01-15 04:09

    Two points I know:

    1. It makes your controllers less testable.
    2. Your views are not strongly typed
    0 讨论(0)
  • 2021-01-15 04:10

    It has the possibility to hit performance at run-time.

    0 讨论(0)
提交回复
热议问题