asp.net - ViewBag 中保存的列表是在 cshtml 视图中打印数据
问题描述
ViewBag.FY
我从控制器中保存了一个列表。在调试期间,它会在 ViewBag 中显示数据。
当我在视图中打印数据时,它不是在打印数据。
这是代码:
@model IEnumerable<MVC4_Theming.HRMS_Tax>
@{
ViewBag.Title = "Index";
var taxSlabsByFinancialYear = ViewBag.FY;
}
<div class="table table-responsive">
<table id="example" class="table table-hover table-striped table-bordered" cellspacing="0">
<thead>
<tr>
<th>No#</th>
<th>Name</th>
<th>Min-Range</th>
<th>Max-Range</th>
<th>Annual-Range</th>
<th>Fix-Amount</th>
<th>(%)-Amount</th>
<th>Year-Slab</th>
<th>IsActive</th>
<th>Action</th>
</tr>
@{
if (ViewBag.FY == null)
{
<p>Please Select Financial Year</p>
}
else
{
int a = 0;
foreach (var item in ViewBag.FY)
{
a++;
<tr>
<td>@a</td>
<td>@item.Name</td>
<td>@item.MinAmountRang</td>
<td>@item.MaxAmountRang</td>
<td>@item.Anuual_Amount</td>
<td>@item.Fix_Amount</td>
<td>@item.Percentage_Amount</td>
</tr>
}
}
}
</thread>
</table>
</div>
</div>
</div>
</div>
请帮助我 - 谁知道这个问题的答案?
提前致谢
解决方案
这是一个工作演示:
模型:
public class FY
{
public string Name { get; set; }
public int MinAmountRang { get; set; }
public int MaxAmountRang { get; set; }
public int Anuual_Amount { get; set; }
public int Fix_Amount { get; set; }
public int Percentage_Amount { get; set; }
}
行动:
public IActionResult TestViewBag()
{
ViewBag.FY = new List<FY> {
new FY { Name="n1", MaxAmountRang=10, MinAmountRang=1, Fix_Amount=3, Percentage_Amount=4, Anuual_Amount=5} ,
new FY { Name="n2", MaxAmountRang=10, MinAmountRang=1, Fix_Amount=3, Percentage_Amount=4, Anuual_Amount=5} ,
new FY { Name="n3", MaxAmountRang=10, MinAmountRang=1, Fix_Amount=3, Percentage_Amount=4, Anuual_Amount=5} ,
};
return View();
}
看法:
@{
ViewBag.Title = "Index";
var taxSlabsByFinancialYear = ViewBag.FY;
}
<div class="table table-responsive">
<table id="example" class="table table-hover table-striped table-bordered" cellspacing="0">
<thead>
<tr>
<th>No#</th>
<th>Name</th>
<th>Min-Range</th>
<th>Max-Range</th>
<th>Annual-Range</th>
<th>Fix-Amount</th>
<th>(%)-Amount</th>
<th>Year-Slab</th>
<th>IsActive</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@{
if (ViewBag.FY == null)
{
<p>Please Select Financial Year</p>
}
else
{
int a = 0;
foreach (var item in ViewBag.FY)
{
a++;
<tr>
<td>@a</td>
<td>@item.Name</td>
<td>@item.MinAmountRang</td>
<td>@item.MaxAmountRang</td>
<td>@item.Anuual_Amount</td>
<td>@item.Fix_Amount</td>
<td>@item.Percentage_Amount</td>
</tr>
}
}
}
</tbody>
</table>
</div>
推荐阅读
- android - AdMob - 示例广告有效,我自己的插页式广告无效
- java - 使用 JSON 值的存储过程不遍历 java 中的对象数组值
- postgresql - 有什么方法可以重命名 PostgreSQL 默认操作符名称?例如,将 EXCEPT 运算符改为 MINUS。这是可行的吗?
- python - Pygame - 零除法错误:浮点除以零
- html - 在浏览器打印机版本中将谷歌图表居中
- javascript - 删除 json_encode 中的双引号
- sql-server - 来自 T-SQL 查询的 Active Directory 更新脚本
- node.js - 我的 nodeJS 应用程序正在发送可疑的 GET/POST 请求。我有病毒吗?
- python - 线性回归梯度
- ios - iOS - 创建核心图像过滤器循环时保留原始图像