I am having an issue sending through a list from a form to a controller to work with and edit. It just destroys the list and passes through just one empty string. I need the list to maintain so that i can add to it in the controller.
The view looks like this:
@using (Html.BeginForm("AddToBasket", "Home", FormMethod.Post))
{
@Html.Hidden("product", product.Product)
@Html.Hidden("basketItems", Model.BasketItems)
<h3>@product.Product (£@product.Price)</h3>
<div class="menu-item-quantity">
<h4>Quanitity: @Html.TextBox("quantity", 0, new { @class = "form-control-quantity" })</h4>
</div>
<input class="btn btn-lg" type="submit" value="Add to basket" />
}
The controller:
public ActionResult AddToBasket(string product, int quantity, List<string>basketItems)
{
var products = new GetProductsList<ProductLookup>().Query().ToList();
var Result = new BuyViewModel
{
Products = products,
BasketItems = basketItems.ToList()
};
return View("Buy", Result);
}
and the model:
public class BuyViewModel
{
public IList<ProductLookup> Products { get; set; }
public List<string> BasketItems { get; set; }
}
How would i get that list through to the controller in one piece??
Session
or whatever repository you want to use) – Grassy