我有这个下拉列表,我希望它回发,并将id传递给控制器。当我更改下拉列表时,此代码将会回发,但正如您所看到的,我传入的硬编码值为3。如何获取所选项的SelectList值以将其传递给控制器?
@using (Html.BeginForm("Index", "PurchaseOrder", new { id = 3 }))
{
@Html.DropDownList("jobStatuses", (SelectList)null, new { onchange = "this.form.submit();" })
}
答案 0 :(得分:2)
我会这样做:
@using (Html.BeginForm("Index", "PurchaseOrder", new { id = "" }))
{
@Html.DropDownList("id", (SelectList)null, new { onchange = "this.form.submit();" })
}
将控件的名称更改为id会将其传递给控制器操作的id参数