我已将一个表单添加到我的默认索引视图中,并为名为'数量'的Html.TextBox添加了一列。当我点击提交后,我把它发送到行动“OrderForm”但是当我调试,我只通过数量值和ITEMNAME和inventory_no为空。谁能帮忙?ASP.MVC - 通过使用表格我将如何传递参数给控制器?
下面是从我的MVC示例代码:
型号:
[Table("inventory")]
public partial class inventory
{
[Key]
[Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int inventory_no { get; set; }
public string name { get; set; }
}
查看:
@model IEnumerable<MYAPP.inventory>
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm("orderForm", "inventories", FormMethod.Post))
{
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<div id="details"></div>
<table class="table">
<tr>
<th>
Quantity
</th>
<th>
Name
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.TextBox("Quantity",0, new { style = "width:30px",
@class = "selectedItem"})
</td>
<td class="itemName"><b>
@Html.DisplayFor(modemItem => item.name)
</b>
</td>
<td>
<a href="#" class="remove" data-url="@Url.Action("Remove", new { id = item.inventory_no })">Remove</a>
@Html.ActionLink("Edit", "Edit", new { inventory_no = item.inventory_no.ToString(), client_no = item.client_no }) |
@Html.ActionLink("Delete", "Delete", new { inventory_no = item.inventory_no.ToString(), client_no = item.client_no })
</td>
</tr>
}
</table>
<input type="submit" value="Submit your order" />
}
控制器:
public ViewResult orderForm (int quantity, string itemName, int? inventory_no)
{
return View();
}
你只有文本框为一个字段为每个项目提交按钮? – AliK
https://puu.sh/t9dNL/3fb3950293.png – TaylorM