c# - 是否可以在 MVC 中为 ViewBag 分配 ID?
问题描述
您好,我正在尝试为 ViewBag 分配 ID,但不确定是否可行。
我有一个循环遍历我的站点数据库的 for 循环。
float[] osiTotal = new float[sites.Count + 1];
foreach (Site s in sites)
{
osiTotal[s.ID] = osiPartCost[s.ID] + osiCompCost[s.ID] + osiItemCost[s.ID];
ViewBag.OSITotal[s.ID] = osiTotal[s.ID];
}
然后在视图页面上看起来像这样
foreach (Site s in sites)
{
<tr>
<td>Total</td>
<td></td>
<td></td>
<td>@ViewBag.OffReportTotal[s.ID]</td>
</tr>
}
但这给了我“无法对可空引用执行运行时绑定”错误消息,所以我想知道我想要做的事情是否可行?
解决方案
推荐阅读
- reactjs - 将输入参数连接到拼接调用中
- javascript - 我有一个代码,它将类存储在本地存储中以用于不同的元素,但其中一个没有存储?任何想法为什么会发生这种情况?
- javascript - DataMap/D3 - 如何重置缩放?
- objective-c - 如何在 Objective-C 中避免用户字符串输入
- google-apps-script - 如何使用带有 ArrayFormula 的自定义函数
- firebase - 如何在 Flutter 中调试 Firestore 安全规则
- wpf - 分组和虚拟化时WPF DataGrid调整大小问题
- python - 将时间戳从 Dataframe 加载到 BigQuery 数据集
- postgresql - postgres 中的索引元组最大大小是多少?
- sql-server - 并行执行 SQL 命令的选项