【发布时间】:2021-01-05 22:59:05
【问题描述】:
我如何能够在列表框中选择多个将传递给控制器的 Post model 参数的项目?
我可以通过按住 CTRL 物理选择多个,但是当我提交时,我收到验证错误消息,“字段 TagId 必须是一个数字。”它只提交选择了一项。
Create View Form showing multiple items selected
列表框
@Html.ListBoxFor(model => model.allTags[0].TagId, new SelectList(Model.allTags, "TagId", "Name"), new { @class = "form-control", @Id = "SelectTags", @style = "width:200px;height:300px;" })
控制器 Post 方法
[HttpPost]
public ActionResult Create(CreateRecipe model)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("ViewRecipes");
}
catch
{
return View();
}
}
谢谢
【问题讨论】:
标签: c# .net asp.net-mvc visual-studio html.listboxfor