たとえば、ビューにリストを渡す次のモデルがあります。
public class ExampleViewModel
{
public int id { get; set; }
public string name { get; set; }
}
私の見解では、私は次のことを持っています:
@model List<ExampleViewModel>
<table>
<tr>
<th>Name</th>
<th>Action</th>
</tr>
@foreach (var x in Model)
{
<tr>
<td>
@Html.DisplayFor(m => x.name)
</td>
<td>
<input type="button" onclick="edit();" value="Edit">
</td>
</tr>
}
</table>
<script type="text/javascript">
function edit(x) {
window.location = "/Home/Edit?id=" + x
}
</script>
私が問題を抱えているのは、 x.id を edit() 関数に渡すことです。私は期待しました:
<input type="button" onclick="edit(@x.id);" value="Edit">
動作しますが、動作しませんでした。
ありがとう