【发布时间】:2014-06-16 03:04:33
【问题描述】:
我正在制作一个 ASP.NET MVC 应用程序,我目前有一个表:
|ID|first name|surname|
1 bob smith Select <- (clickable)
我目前正在控制器中获取数据并将其传递给 ViewBag 中的视图,然后使用 razor 创建表。
<table>
<thead>
<tr>
<th>Id</th>
<th>First name</th>
<th>surname</th>
</tr>
</thead>
@foreach (var name in ViewBag.names)
{
<tr>
<td>@name.Id</td>
<td>@name.firstname</td>
<td>@name.surname</td>
<td>Select</td> <- shall make this clickable
</tr>
}
</table>
有没有办法从表中获取信息(当我单击选择按钮时)。理想情况下只是该行的 ID。
我也在尽量避免使用 javascript
目的是在我的控制器中调用 actionResult 方法,传入 id 作为参数
public ActionResult Login(int id)
{
// do stuff
}
【问题讨论】:
-
这看起来像XY problem。您实际上要做什么,根据该行的 ID 在单击该行的按钮时执行一个操作?
-
请出示您的代码
-
@alex 我想在我的控制器中调用一个 actionResult 方法,传入 id 作为参数
-
@Shoe 为你添加了一些代码
-
@BrianPeach 假设我正确理解了这个问题,我提出的解决方案应该符合标准
标签: c# asp.net sql asp.net-mvc razor