【发布时间】:2023-03-16 16:45:01
【问题描述】:
这更像是一个通用的架构问题:
我正在尝试确定我的程序员是否可以使用“ViewBags”将数据传递给已经接受模型的视图。
我个人的偏好是避免使用 ViewBags 并构建包含视图所需的所有数据的稳健模型:
方法一:
MODEL A:
- List of Employees
- Nullable integer, indicating which item from the list is currently selected
- string firstName (empty if index is null)
- string lastname (empty if index is null)
方法2:
MODEL A:
- List of Employees
ViewBag:
- ViewBag.Index (indicating which item from the list is currently selected)
- ViewBag.FirstName
- ViewBag.LastName
谁能想到为什么方法 2 比方法 1 更好的论点?
感谢您的意见
【问题讨论】:
标签: asp.net-mvc viewbag asp.net-mvc-viewmodel