我想使用FormCollection向Controller发送选项值,但我可以在FormCollection数组中获取选择名称信息。这里哪里错了?谢谢你的帮助。
这是我的观点(这里的模型是产品);
@using (Html.BeginForm("AddToCart", "Home", new { id = Model.Id }, FormMethod.Post))
{
<div class="product-sides-part">
<div class="product-sides-part-itemcontainer">
@if (Model.Size == "0")
{
<select name="Drink1">
@foreach (var item in ViewBag.Drinks)
{
<option id="Drinks1" value="value">@item.Name</option>
}
</select>
}
这是我的控制者;
public ActionResult AddToCart(FormCollection formCollection, int id, string root, int quantity = 0)
{
if (root == "cart" || root == "Checkout")
{
if (Session["cartpastahemen"] == null)
{
Cart s = new Cart();
Product eklenecek = db.Products.Find(id);
switch (eklenecek.Size)
{
case"0":
s.AddToCart(new CartProduct
{
Drinks1=formCollection["Drinks1"],
Drinks2=null,
Drinks3=null,
Cips1 = formCollection["Cips1"],
Cips2=null,
Cips3=null,
Snack1 = formCollection["Snack1"],
Snack2=null,
Snack3=null,
Size=eklenecek.Size,
ProductId = eklenecek.Id,
Category = eklenecek.Category.Name,
Quantity = quantity,
Price = eklenecek.DiscountedPrice,
PhotoPath = eklenecek.Photos.FirstOrDefault() != null ? eklenecek.Photos.FirstOrDefault().PhotoPath : "Resim_yok.gif",
Name = eklenecek.Name,
});
break;
答案 0 :(得分:0)
我已经解决了。我写错了值=&#34;值&#34;而不是价值&#34; @ item.name&#34;。我已经改变了,它已经解决了。