【发布时间】:2021-07-06 03:17:39
【问题描述】:
所以我有一个使用 DropDownListFor 创建的下拉菜单,它显示正常,但数据未正确发送到控制器。
@using (Html.BeginForm("sendTestData", "Dashboard", FormMethod.Post))
{
var cnt = 0;
foreach (string question in ViewBag.Questions)
{
<h3>@Html.DisplayFor(x => question)</h3>
@Html.DropDownListFor(x => x.answers[cnt], new SelectList(ViewBag.Answers))
cnt++;
}
<input id="Submit" type="submit" value="submit" />
}
正在使用的模型有一个名为 answers 的列表,我正在尝试将创建的每个下拉列表的值传递到模型的列表中。 正在使用的控制器具有以下功能
public void sendTestData(Model model)
{
//business logic
}
型号:
public class Model
{
public List<string> answers = new List<string>();
}
我检查了列表的值:model.answers,它只是一个空列表,没有数据放入其中。
【问题讨论】:
标签: c# asp.net entity-framework model-view-controller