DropDownList不传递其他参数

时间:2016-09-18 14:04:55

标签: drop-down-menu

我想将从DropDownlist中选择的数字传递给其他Controller中的GET Create方法。它看起来像:

[HttpGet]
public ActionResult Details(int? id, string error)
    {
        {...}
        var numbers = Enumerable.Range(1, 100);
        ViewBag.Quantity = numbers.Select(i => new SelectListItem { Value = i.ToString(), Text = i + "%" });
        return View(viewModel);
    }

public ActionResult Create(int ID, int quantity)
        {
            {...}
        }

详细信息视图如下:

<div>
    @if (Model.ItemRent.Zatwierdzony == false)
    {
        using (Html.BeginForm("Create", "ItemRentLists", new { ID = @Model.ItemRent.ItemRentID }, FormMethod.Get))
        {
            @Html.DropDownList("quantity", new SelectList(ViewBag.Quantity, "Text", "Value"))
            <input type="submit" value="Dodaj przedmioty"/>
        }
    }
</div>

DropDownList在Create方法中没有将值传递给“quantity”参数,这里有什么问题?

1 个答案:

答案 0 :(得分:0)

好的,我改变了@Html.DropDownList("quantity", ViewBag.Quantity as SelectList),现在它可以正常工作。