我在 cshtml 文件中有一个下拉列表:
var kategorie_wlasna = new SelectList(
(from z in Model.Kategoria
where !formReadOnly || z.Id == Model.KategoriaWlasnaId
select z),
"Id",
"Nazwa");
...
@Html.DropDownListFor(
model => model.KategoriaWlasnaId,
kategorie_wlasna,
"----",
htmlClassDropDownListDef)
在我的 viewModel 中,我的属性没有任何必需的注释:
public long KategoriaWlasnaId { get; set; }
但该字段仍为必填项。在浏览器中我得到:
<select class="input-validation-error form_object1" data-val="true" data-val-number="The field KategoriaWlasnaId must be a number." data-val-required="The KategoriaWlasnaId field is required." id="KategoriaWlasnaId" name="KategoriaWlasnaId">
<option value="">-----</option>
<option value="1227">Wykroczenie</option>
<option value="1228">Przestępstwo</option>
</select>
我错过了什么?