我无法在输入提交按钮中将ID值传递给控制器方法。我试图根据用户单击O按钮的哪一行来传递ActionItemID值。我似乎无法在控制器中调用该值。
@model SQLApplication.Models.ActionItems.ActionItemsViewModel
<table class="table table-condensed table-action-items">
<tr>
<th>@Html.DisplayNameFor(model => model.Description.Status)</th>
<th>@Html.DisplayNameFor(model => model.Description.Principal)</th>
<th>@Html.DisplayNameFor(model => model.Description.CompanyName)</th>
<th>@Html.DisplayNameFor(model => model.Description.ActionItem)</th>
<th>@Html.DisplayNameFor(model => model.Description.Owners)</th>
<th>@Html.DisplayNameFor(model => model.Description.DueDate)</th>
<th>@Html.DisplayNameFor(model => model.Description.UpdatedDate)</th>
<th>@Html.DisplayNameFor(model => model.Description.CreatedDate)</th>
<th>@Html.DisplayNameFor(model => model.Description.Sales)</th>
<th></th>
</tr>
@foreach (var item in Model.Items)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.Status)</td>
<td>@Html.DisplayFor(modelItem => item.Principal)</td>
<td>@Html.DisplayFor(modelItem => item.CompanyName)</td>
<td>@Html.DisplayFor(modelItem => item.ActionItem)</td>
<td>@Html.DisplayFor(modelItem => item.Owners)</td>
<td>@Html.DisplayFor(modelItem => item.DueDate)</td>
<td>@Html.DisplayFor(modelItem => item.UpdatedDate)</td>
<td>@Html.DisplayFor(modelItem => item.CreatedDate)</td>
<td>@Html.DisplayFor(modelItem => item.Sales)</td>
<td class="right"><input type="submit" name="O" value="@item.ActionItemId" class="btn btn-default" onclick="location.href='@Url.Action("Open", "ActionItems")'" /></td>
<td class="right"><input type="submit" value="P" class="btn btn-default" onclick="location.href='@Url.Action("Index", "ActionItems")'" /></td>
<td class="right"><input type="submit" value="C" class="btn btn-default" onclick="location.href='@Url.Action("Index", "ActionItems")'" /></td>
</tr>
}
</table>
答案 0 :(得分:0)
您正在执行的重定向中没有任何值:
location.href='@Url.Action("Open", "ActionItems")'
如果要包含id
值,请将其添加到Url.Action
方法调用中:
location.href='@Url.Action("Open", "ActionItems", new { id = item.ActionItemId })'
您似乎确实要尝试使用value
属性,该属性本身对于通过“提交”按钮提交的<form>
很有用。但是我怀疑没有<form>
时,您的按钮没有执行任何操作,因此您添加了JavaScript重定向。两种方法都可以,真的。关键区别在于: