我有这个:
@Html.DropDownListFor(x => x.SelectedValue, new SelectList(Model.SomeList, "Value", "Text"))
并希望它呈现为这样:
<select required>
<option>...</option>
...
我该怎么做?
用这个:
@Html.DropDownListFor(x => x.SelectedValue, new SelectList(Model.SomeList, "Value", "Text"), new {required = "required"})
它不会实现速记<select required
,但应该具有相同的效果。尽管我发现您可以使用
@Html.DropDownListFor(x => x.SelectedValue, new SelectList(Model.SomeList, "Value", "Text"), new {required = (string)null})
这有点难看。
尝试以下
@Html.DropDownList("PlanType", null, "Select Plan Type", htmlAttributes: new { @class = "form-control", required = "Select Plan Type" })
VB.NET
@Html.DropDownListFor(Function(Model) Model.ProgramTypeId, New SelectList(Model.allPrograms,
"ProgramTypeId", "ProgramName"), "Select Program....",
New With {Key .class = "form-control", Key .required = "Required"})