2
我有一個應用程序,我需要將選擇的下拉列表值與表單發佈方法上的模型一起傳遞迴控制器。下拉字段不是我模型的一部分,所以它的值不會傳遞給表單上的控制器。我想在不使用ajax或javascript的情況下實現此目的。請幫忙?下拉選定的值應該作爲字符串發佈到控制器
這裏是我的控制器代碼:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(List<ClassSubject> ci, string U_Dropdown)
{
// db logic
}
查看代碼:
@using (Html.BeginForm("Create", "coursesubject", new {//have to pass dropdown selected value as string here }, FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div>
@Html.DropDownList("name", new SelectList(ViewBag.SelectedDepartment, "Value", "Text"), "", new { @class = "form-control" })
</div>
//// my model fields
}
將方法中的參數更改爲'string name'以匹配下拉列表的名稱。 –
好的,我應該在BeginForm中爲新的{}傳遞什麼? – Poonam
什麼都沒有。 'DropDownList()'創建'