I've added a form to my default Index view with an added column for a Html.TextBox named 'Quantity'. When I hit Submit I'm sending it to the Action "OrderForm" but when I debug I only pass the Quantity value and the itemName and inventory_no is null. Can anyone help?
Below is sample code from my MVC:
Model:
[Table("inventory")] public partial class inventory { [Key] [Column(Order = 0)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int inventory_no { get; set; } public string name { get; set; } } View:
@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" /> } Controller :
public ViewResult orderForm (int quantity, string itemName, int? inventory_no) { return View(); } 