【发布时间】:2021-08-27 06:42:50
【问题描述】:
我希望表单中的复选框作为所选复选框的所有值的列表返回
foreach (string url in ListOfPhotoURLs)
{
<div class="form-check form-check-inline">
<input asp-for="Input.ChosenPhotos" class="form-check-input" type="checkbox" id="PhotosChosen" value="@url">
<img src="@url" alt="photo from url @url" width="250">
<span class="text-danger" asp-validation-for="Input.ChosenPhotos"></span>
</div>
}
其中Input.ChosenPhotos 是List<string> 类型,当提交表单时,我希望我的列表中填充与选中复选框对应的所有值(url)
当我运行时,我收到一个错误,基本上说复选框只能返回一个布尔值或字符串。不是字符串或布尔值的列表。
问题是我的列表长度不确定,所以我不能有一个输入模型,每个复选框都有一个单独的属性。
我不确定这里的最佳解决方案是什么?
顺便说一句,我正在使用 Razor 页面
【问题讨论】:
标签: c# forms asp.net-core checkbox