c# - 通过链接单击将一个 int 值从视图传递到操作
问题描述
在我的视图中,我有一个关于表格的 for 循环。我能够显示结果。但是当我点击任何链接时。我得到一个空点异常。我发现这是因为循环结束了
@model List<MyMainModel>
@using System.Collections;
@using System.Web;
@{
ViewData["Title"] = "Display";
}
<h1>Display</h1>
<table border="1" cellpadding="20" style="table-layout:fixed">
<tr>
<th>
UserName
</th>
<th>
PAssword
</th>
<th>
Email
</th>
<th colspan="2">
Options
</th>
</tr>
@{ for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
@Model.ElementAt(i).USERNAME
</td>
<td>
@Model.ElementAt(i).PASSWORD
</td>
<td>
@Model.ElementAt(i).EMAIL
</td>
<td >
<a href="@Url.Action("RemoveRow", "MyMain")">Remove</a>
</td>
<td>
<a href="@Url.Action("EditRow", "MyMain")">Edit</a>
</td>
</tr>
}
}
</table>
当我单击 Remove 时,我想将相应 Element 的 ID 传递回 RemoveRow Action 我该怎么做
解决方案
@Url.Action("RemoveRow", "MyMain", new { id = i })
推荐阅读
- groovy - JMeter jp@gc-WebDriver Sampler — 从 MS Excel 电子表格运行网页
- actionscript-3 - 在AS3中,我可以使2个以上的输入文本字段的文本相同吗?
- python - 不同起始条件下的时间序列预测
- python - 我无法使用 pysimplegui 将图像下方的元素向上移动
- elasticsearch - 在 ElasticSearch 中存储时间相关数据
- jquery - jquery文件上传,1.9MB图片文件太大?
- amazon-web-services - AWS s3 通过 CORS 或接入点提供访问?403禁止错误
- c++ - 指向链表中指针的指针在每次调用主函数后都不能保留指针。为什么?
- mysql - MariaDB:我的存储过程没有返回任何行
- python - 如何设置“/*”路径以捕获 FastAPI 中的所有路由?