使用此代码,我无法将带有模型绑定的PlayerViewModel传递给我的操作方法
@foreach (var player in Model)
{
<tr>
<td><img class="mini-avatar" src="@player.AvatarURL" /></td>
<td>@player.Username</td>
<td>@player.XP</td>
<td><button class="btn btn-info btn-lg" type="button" data-toggle="modal" data-target="#myModal">Battle!</button></td>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Commencing Battle</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to fight ?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
</div>
</div>
</div>
</div>
</tr>
在下面,您可以看到以下代码片段:
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
</div>
问题是,例如,如果我有10个玩家,则foreach将循环10次,并吸引每个玩家并将其绑定到具有3个属性的asp-route-data="@player"
中,然后经过10次,它将进入我的在页面上,当我选择战斗并打开模式对话框时,选择确认,它将发送给我asp-controller="Game" asp-action="Battle"
可以,但是传递的值为null。解决任何人?我将非常感谢!我正在使用HttpGet作为此Action的属性。这是问题吗?